Hi All,
Can we pull the list of VM's running on specific host e.g. C:\temp\hostname.txt. from power cli script ?
Want to include cluster name also and power state of VM's
thanks
vmk
Oops you are right. Now, i can see the report without any flaw.
Try something like this
Get-VM |
Select @{N='Cluster';E={(Get-Cluster -VMHost $esx).Name}},
@{N='VMHost';E={$esx.Name}},
@{N='VM';E={$_.Name}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Can we add the VM's state whether it's powered on off?
thanks
vmk
Sure
Get-VM |
Select @{N = 'Cluster'; E = {(Get-Cluster -VMHost $esx).Name}},
@{N = 'VMHost'; E = {$esx.Name}},
@{N = 'VM'; E = {$_.Name}},
PowerState
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Sorry for the delayed reply. I missed out sharing that the script unable to read hostname in FQDN. Can you add that too?
Try like this
Get-VM |
Select @{N = 'Cluster'; E = {(Get-Cluster -VMHost $esx).Name}},
@{N = 'VMHost'; E = {$esx.Name}},
@{N = 'VMHost FQDN';E={"$($esx.NetworkInfo.HostName).$($esx.NetworkInfo.DomainName)"}},
@{N = 'VM'; E = {$_.Name}},
PowerState
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
the output generated without any error but VM's state is not reflecting whether it's powered off or on
Cluster | VMHost | VMHost FQDN | VM |
thanks
vmk
Is that your output header?
There is no PowerState property. Or is that because it doesn't fit on your screen? Try to pipe the output to Format-List.
Can you show me the code you are using? It looks like the last line from my code is missing.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Get-VMHost -Name (Get-Content -Path C:\temp\hostname.txt) -PipelineVariable esx |
Get-VM | Select @{N = 'Cluster'; E = {(Get-Cluster -VMHost $esx).Name}},
@{N = 'VMHost'; E = {$esx.Name}},
@{N = 'VMHost FQDN';E={"$($esx.NetworkInfo.HostName).$($esx.NetworkInfo.DomainName)"}},
@{N = 'VM'; E = {$_.Name}} |
Export-Csv -Path C:\Temp\VM-lists_runningonHost.csv -NoTypeInformation -UseCulture
You dropped the last line that contains PowerState
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Oops you are right. Now, i can see the report without any flaw.
Was it the intention that you marked your own reply as the correct answer?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference