Export-CSV

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

}

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:

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

$results |  Export-csv

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