VMware Cloud Community
Mallik7
Enthusiast
Enthusiast
Jump to solution

looking for a script

hello, looking for a powercli script to help to get the list of VMs from a vCenter along with cluster name and vCenter.

format should be like this -

vCenter name - VM name - Cluster name

this output should be saved in a .csv format

TIA

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Get-Cluster -PipelineVariable cluster |

Get-VM | ForEach-Object -Process {

    New-Object -TypeName PSObject -Property @{

        vCenter = ([System.Uri]$_.ExtensionData.Client.ServiceUrl).Host

        Cluster = $cluster.Name

        VM = $_.Name

    }

} | Select vCenter, VM, Cluster |

Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

Get-Cluster -PipelineVariable cluster |

Get-VM | ForEach-Object -Process {

    New-Object -TypeName PSObject -Property @{

        vCenter = ([System.Uri]$_.ExtensionData.Client.ServiceUrl).Host

        Cluster = $cluster.Name

        VM = $_.Name

    }

} | Select vCenter, VM, Cluster |

Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Mallik7
Enthusiast
Enthusiast
Jump to solution

thanks, but, it is not capturing the vCenter name. can you please have look

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Corrected


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast
Jump to solution

its working as expected. thank you LucD

Reply
0 Kudos