locked
Export-csv RRS feed

  • Question

  • good morning,

    I am newbie in powershell, and would like you guys to help.
    I am creating a powershell script that runs every day at 02:00 in the morning.
    The script is very simple, a Get-WmiObject to get the information Caption and CSName, all within a case, which runs on a specific range of IP.

    Today the output of this script is being played in a .txt file
    Would help to play it in a .csv file. I took a read on the export-csv, but I'm having a lot of difficulty. Could someone help me pr kindness?

    Follow my script:

    for($i=33; $i -le 50; $i++){

        Get-WmiObject Win32_OperatingSystem -ComputerName 10.195.230.$i | Format-Table Caption,CSName >> C:\Test.txt

    }
    Friday, May 29, 2015 1:28 PM

Answers

  • Won't work.  Do it like this.

    33..50 | 
        %{
            Get-WmiObject Win32_OperatingSystem -ComputerName 10.195.230.$_
        } | 
        select Caption,CSName | 
        export-csv C:\Test.csv -NoType



    \_(ツ)_/

    • Marked as answer by brncs Friday, May 29, 2015 2:55 PM
    Friday, May 29, 2015 2:17 PM

All replies

  • You could change your code this way...

    for($i=33; $i -le 50; $i++){
    
        Get-WmiObject Win32_OperatingSystem -ComputerName 10.195.230.$i | select Caption,CSName | export-csv C:\Test.csv
    
    }

    Without seeing your other non-working code or knowing more about your issues, I can't really tell you what was wrong with it, but this should do what you're looking for.

    Friday, May 29, 2015 1:51 PM
  • Won't work.  Do it like this.

    33..50 | 
        %{
            Get-WmiObject Win32_OperatingSystem -ComputerName 10.195.230.$_
        } | 
        select Caption,CSName | 
        export-csv C:\Test.csv -NoType



    \_(ツ)_/

    • Marked as answer by brncs Friday, May 29, 2015 2:55 PM
    Friday, May 29, 2015 2:17 PM
  • Thank you man ! Excellent :D
    Friday, May 29, 2015 2:56 PM