I am trying to create a script to collect the VMname, the cluster it is in and the datacenter it is in. Right now I have a for loop going through each VM and doing a get-cluster and then a get-datacenter.
Here is the loop:
$VMS = Get-VM
ForEach
($VM in $VMS){
$DC = Get-Datacenter -VM $VM
$CL = Get-Cluster -VM $VM
Add-Content $Outfile2 $VM~$DC~$CL~$DefaultVIServer -Encoding Ascii}
Wanted to see if there was a better way to query for that in one command? I am just getting started with powershell so figured someone could shed some light on querying the VC for info.
Thanks
Forget command line complex commands..
use this instead: http://robware.net/
Nice tools if I only had 1 VC. I have 16 VCs. Trying to write a powershell script to collect information for our technical support groups so they can locate VMs.
Since you posted in the PowerCLI Community I assume you want to script this :smileymischief:
Try this, it saves the result to a CSV file, and it's a bit more PowerShell
Get-VM | Select Name, @{N="Datacenter";E={(Get-Datacenter -VM $_).Name}}, @{N="Cluster";E={(Get-Cluster -VM $_).Name}}, @{N="vCenter";E={$DefaultVIServer.Name}} | Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference