Site Tools


vmware:scripts:getinfo

This is an old revision of the document!


Get infos of VMs

This script need to be executed via PowerCLI

#Remove user and pass for pass-through auth
Connect-VIServer -Server <HOSTNAME>
#Connect-VIServer -Server <HOSTNAME> -User <USERNAME> -Password <PASSWORD>
 
$allvminfo = @()
$vms = Get-Vm
$targetfile = "C:\Temp\VMInfo.csv"
 
foreach($vm in $vms){
$vminfo = "" | Select Name, Host, Network, PowerState, CPUCount, RAMAssigned, ProvisionedSpace, UsedSpace, UnusedSpace, ConfiguredOS, RunningOS
$VMHost = Get-VM $vm.Name | select Host 
$VMHost = $VMHost.Host 
$VMNetwork = Get-VM $vm.Name | Select {@($_.guest.IPAddress[0])}
$VMPowerState = Get-VM $vm.Name | select PowerState 
$VMPowerState = $VmPowerState.PowerState 
$CPUCount = Get-VM $vm.Name | select NumCpu 
$CPUCount = $CPUCount.NumCpu 
$RAMAssigned = Get-VM $vm.Name | select MemoryGB 
$RAMAssigned = $RAMAssigned.MemoryGB 
$vmview = Get-VM $vm.Name | Get-View
$ProvisionedSpace = Get-VM $vm.Name | select ProvisionedSpaceGB
$ProvisionedSpace = $ProvisionedSpace.ProvisionedSpaceGB
$ProvisionedSpace = [math]::round($ProvisionedSpace, 2)
$vmview.Storage.PerDatastoreUsage.Committed.gettype() 
$UsedSpace = [math]::round(($vmview.Storage.PerDatastoreUsage.Committed/1024/1024/1024), 2) 
$UsedSpace =$UsedSpace.ToString() 
$UsedSpace = $UsedSpace + " GB" 
$UnUsedSpace = [math]::round(($vmview.Storage.PerDatastoreUsage.UnCommitted/1024/1024/1024), 2)
$UnUsedSpace =$UnUsedSpace.ToString() 
$UnUsedSpace = $UnUsedSpace + " GB" 
$ProvisionedSpace =$ProvisionedSpace.ToString() 
$ProvisionedSpace = $ProvisionedSpace + " GB" 
$ConfiguredOS = Get-VM $vm.Name | Select {@($_.ExtensionData.Config.GuestFullname)}
$RunningOS = Get-VM $vm.Name | Select {@($_.Guest.OsFullName)}
 
	$vminfo.Name = $vm.Name
	$vminfo.Host = $VMHost
	$vminfo.Network = $VMNetwork
	$vminfo.PowerState = $VMPowerState
	$vminfo.CPUCount = $CPUCount
	$vminfo.RAMAssigned = $RAMAssigned
	$vminfo.ProvisionedSpace = $ProvisionedSpace
	$vminfo.UsedSpace = $UsedSpace
	$vminfo.UnUsedSpace = $UnUsedSpace
	$vminfo.ConfiguredOS = $ConfiguredOS
	$vminfo.RunningOS = $RunningOS
	$allvminfo += $vminfo
}
$allvminfo | Select Name, Host, Network, PowerState, CPUCount, RAMAssigned, ProvisionedSpace, UsedSpace, UnusedSpace, ConfiguredOS, RunningOS | Export-Csv $targetfile -noTypeInformation
 
#The following lines will clean up the .csv
(Get-Content $targetfile).replace('@{@($_.guest.IPAddress[0])=', '') | Set-Content $targetfile
(Get-Content $targetfile).replace('@{@($_.ExtensionData.Config.GuestFullname)=', '') | Set-Content $targetfile
(Get-Content $targetfile).replace('@{@($_.Guest.OsFullName)=', '') | Set-Content $targetfile
(Get-Content $targetfile).replace('}"', '"') | Set-Content $targetfile

vmware/scripts/getinfo.1517592055.txt.gz · Last modified: 2018/02/02 18:20 (external edit)