0

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?

3
  • I believe you need to hard code what data and where they are to be placed in excel instead of using out-default Commented Jul 20, 2015 at 11:42
  • Without using out-default its not giving desired result, since it displays list in incorrect order. Like all server list once and Vm infos at once instead of Server and then Vm info pattern. Commented Jul 20, 2015 at 11:57
  • Possible duplicate of stackoverflow.com/questions/29973404/…. I'd start by learning the basics of Export-CSV by using it with Get-Process for example. Commented Aug 14, 2015 at 4:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.