Site Tools


vmware:scripts:getinfo

Get infos of VMs

The scripts need to be executed via PowerCLI

Full vCenter

#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-VMHost -VM $vm 
$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

Host CPUs

#Remove user and pass for pass-through auth
Connect-VIServer -Server <HOSTNAME>
#Connect-VIServer -Server <HOSTNAME> -User <USERNAME> -Password <PASSWORD>
 
$targetfile = "C:\Temp\HostCPUs.csv"
 
get-vmhost | Select name,@{N=“# CPU“;E={($_| Get-View).Hardware.CpuInfo.NumCpuPackages}},@{N="Cores per CPU";E={($_| Get-View).Hardware.CpuInfo.NumCpuCores /($_| Get-View).Hardware.CpuInfo.NumCpuPackages}},@{N=“#Cores“;E={($_| Get-View).Hardware.CpuInfo.NumCpuCores}}| Export-csv $targetfile –NoTypeInformation

vmware/scripts/getinfo.txt · Last modified: 2018/04/24 17:51 by lunetikk