VM inventory using Powershell
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Scope User -Confirm:$false
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Scope User -Confirm:$false
#$cred = Get-Credential Domain\username
Connect-VIServer VCenter-Name -Credential $cred -force
& { foreach ($vCenterServer in $DefaultVIServers)
{
$VMHostTable= @{}
foreach ($VMHostView in (Get-View -Server $vCenterServer -ViewType HostSystem -Property Name))
{
$VMHostTable[“$($VMHostView.MoRef.Value)”] = $VMHostView.Name
}
$DatastoreTable = @{}
foreach ($DatastoreView in (Get-View -Server $vCenterServer -ViewType Datastore -Property Name))
{
$DatastoreTable[“$($DatastoreView.MoRef.Value)”] = $DatastoreView.Name
}
Get-View -Server $vCenterServer -ViewType VirtualMachine -Filter @{“Config.Template”=”False”} -Property Name,
Runtime.Host,
Guest.GuestFullName,
Runtime.PowerState,
Guest.IPAddress,
Guest.Net,
Config.Annotation,
Datastore,
Config.Tools.ToolsVersion |
Select-Object -Property @{N=”vCenter”;E={$vCenterServer.Name}},
@{N=”VMHost”;E={$VMHostTable[“$($_.Runtime.Host.Value)”]}},
@{N=”VM”;E={$_.Name}},
@{N=”Powerstate”;E={$_.Runtime.PowerState}},
@{N=”Guest OS”;E={$_.Guest.GuestFullName}},
@{N=”IP Address”;E={@($_.Guest.IPAddress)}},
@{N=”MACAddress”;E={$_.guest.net.Macaddress}},
@{N=”Datastores”;E={
$DatastoreNames = foreach ($Datastore in ($_.Datastore))
{$DatastoreTable[“$($Datastore.Value)”]}
[string]::Join(‘,’,($DatastoreNames))}
},
@{N=”VMware Tools version”;E={$_.Config.Tools.ToolsVersion}},
@{N=”Notes”;E={$_.Config.Annotation}}
}} |
Export-Csv -Path “c:\temp\VMsInfo-$(Get-Date -UFormat ‘%Y%m%d-%H.%M.%S’).csv” -NoTypeInformation -UseCulture
#Get-View -Server $vCenterServer -ViewType VirtualMachine -Filter @{“Config.Template”=”False”} -Property Name, @{N=”IP Address”;E={@($_.Guest.IPAddress)}}