Based on my question yesterday for getting all VM's list, I am trying to export data from a foreach loop to an Excel file.
But it seems to be creating a blank CSV file and not writing anything inside. If I try the query without foreach loop it works fine. Any idea what changes are required here?
$name= get-content C:\monitor\Serverlist\Serverlist.txt
foreach($nam1 in $name)
{
Write-output $nam1
Get-VM -computername $nam1 |out-default |Select Name,State,Status,Uptime | Export-Csv -path "c:\report\VMList.csv" –NoTypeInformation
}
Any ideas?
Export-CSVby using it withGet-Processfor example.