Export-CSV

Welcome Forums General PowerShell Q&A Export-CSV

Viewing 2 reply threads
  • Author
    Posts
    • #262763
      Participant
      Topics: 3
      Replies: 6
      Points: 46
      Rank: Member

      Hi Guys.

      Hope someone might be able to assist with a little script i am trying to get working. I have this code i knocked up that will connect to each server in the text file and return the disk provisioning type.  Now this works but ideally i want to be able to take the output in to CSV and include the Provisioning Type but also the computer name from $vmName

      I am a bit stuck on the Export-CSV part. Any ideas?

      Thanks in advance.

      ———

      foreach($vmName in (Get-Content -Path C:\vmnames.txt)){

      get-disk -CimSession $vmName | ft ProvisioningType | Export-csv

      }

    • #262766
      Participant
      Topics: 16
      Replies: 1794
      Points: 3,300
      Helping Hand
      Rank: Community Hero

      Powershell Gotcha. Format-Table (ft) ends the pipeline. The primary purpose is formatting the content in the Powershell console, not outside the console. The pipeline is to pass data along to another command, but the ft basically does not pass data and ends the pipeline. Here is something to get you going:

    • #262769
      Participant
      Topics: 3
      Replies: 6
      Points: 46
      Rank: Member

      Everyday is a school day. Thank you so much for correcting my issue. I changed the code a little to fit my needs.

      Again appreciate  the clear reply.

      $results = foreach($vmName in (Get-Content -Path C:\vmnames.txt)){
      get-disk -CimSession $vmName | select PSComputerName, ProvisioningType
      }

      $results | Export-csv

Viewing 2 reply threads
  • You must be logged in to reply to this topic.