Skip to content

Instantly share code, notes, and snippets.

@sudo-battlekafer
Created September 2, 2022 14:14
Show Gist options
  • Save sudo-battlekafer/d9f1aa4e3dd5d471445a39d1dfccada7 to your computer and use it in GitHub Desktop.
Save sudo-battlekafer/d9f1aa4e3dd5d471445a39d1dfccada7 to your computer and use it in GitHub Desktop.
Powercli VM Report
#import PoSH modules
Write-Verbose -Message "Loading Modules..." -Verbose
Get-Module -ListAvailable VMware* | Import-Module | Out-Null
#connect to VCenter
$path = "C:\Users\$env:UserName\.ssh\vmca.xml"
if(!(test-Path $path)){
Write-Host "Please create VMWare credentials file with the command"
Write-Host "New-VICredentialStoreItem -Host <vCenter server name/IP> -User <User name of vCenter server administrator> -Password <Password> -File <Location where you want to save the file to along with file name>"
Write-Host "Example: New-VICredentialStoreItem -Host vcenter.example.com -User joe.smith@example.com -Password 12345678910$# -File C:\Users\$env:UserName\.ssh\vmca.xml"
break
}
$credentials = Get-VICredentialStoreItem -file $path
Write-Host "Connecting to VCenter"
connect-viserver $credentials.Host -User $credentials.User -Password $credentials.Password
#Add VM properties for vmtools version
Write-Host "Adding VM Properties for vmtools" -ForegroundColor Yellow
New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine -ValueFromExtensionProperty 'Config.tools.ToolsVersion' -Force
New-VIProperty -Name ToolsVersionStatus -ObjectType VirtualMachine -ValueFromExtensionProperty 'Guest.ToolsVersionStatus' -Force
#Get VM info
Write-Host "Gathering VM info" -ForegroundColor Yellow
get-cluster | Get-VM | Select Name, Folder, @{N="IP Address";E={@($_.guest.IPAddress[0])}}, @{N='FQDN';E={$_.ExtensionData.Guest.IPStack[0].DnsConfig.HostName, $_.ExtensionData.Guest.IPStack[0].DnsConfig.DomainName -join '.'}}, Guest, HardwareVersion, ToolsVersion, ToolsVersionStatus, PowerState, NumCpu, MemoryGB, ProvisionedSpaceGB, UsedSpaceGB | Export-Csv C:\Temp\VMinfo-$(get-date -f yyyy-MM-dd).csv -NoTypeInformation
Write-host "C:\Temp\VMinfo-$(get-date -f yyyy-MM-dd).csv" -ForegroundColor Green
Disconnect-viserver -server * -confirm:$false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment