Created
August 6, 2020 08:18
-
-
Save cernoel/faa7e80edeae52545f7809588cb7ad0c to your computer and use it in GitHub Desktop.
get guest data from vmware cluster with powercli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://communities.vmware.com/thread/278559 | |
$Destination = "/mnt/backup0/vmx/" | |
Connect-VIServer -Server <server> -User <user> -Password <password> | |
$ClusterReport=@() | |
$vms = Get-VM | |
foreach($item in $vms){ | |
$GeneralProp=[ordered]@{ | |
'ComputerName'=$item.Name; | |
'PowerState'=$item.PowerState; | |
'VMware Tools'=$item.Guest.ToolsVersion; | |
'Num CPU'=$item.NumCpu; | |
'Memory GB'=$item.MemoryGB; | |
'Cluster'=$item.VMHost.Parent.Name; | |
'Host'=$item.VMHost; | |
'Host Build #'=$item.VMHost.Build; | |
'ResourcePool'=$item.ResourcePool; | |
} | |
$hdd = 1 | |
# add disk infos to property object | |
$item | Get-HardDisk | foreach { | |
$GeneralProp.Add("HDD$($hdd) Name",$_.Name) | |
$GeneralProp.Add("HDD$($hdd) Datastore",$_.FileName.split(" ")[0].TrimStart("[").TrimEnd("]")) | |
$GeneralProp.Add("HDD$($hdd) Path",$_.FileName.split(" ")[1].TrimStart("[").TrimEnd("]")) | |
$GeneralProp.Add("HDD$($hdd) Capacity",$_.CapacityGb) | |
$dsname = $_.Filename.split(" ")[0].TrimStart("[").TrimEnd("]") | |
$hdd++ | |
} | |
$ClusterReport += New-Object -TypeName psobject -Property $GeneralProp | |
} | |
$ClusterReport | Export-CSV vmreport.csv -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment