########################################################################### # # NAME: VM Inventory # # AUTHOR: Joshua Schofield # # COMMENT: Script to use when wanting Datastore, Host, Name, PowerState, OS, IP, and vCenter server information for all VMs. # # # VERSION HISTORY: 6 # # VERSION DATE: 08/10/2012 # # # PreReqs: Must have vSphere Client and PowerCLI installed # # # # ########################################################################### # Adding all snapins to current PS Session Get-PSSnapin -Registered | Add-PSSnapin # Set Variables for Outfile and vCenter Server(s) $outfile = Read-Host -Prompt "Type the entire path and file name (c:temptest.csv) for output file:" $vc = Read-Host -Prompt 'Enter vCenter Server FQDN or IP Address (If multiple type @("hostname","hostname2"):' # Popup Window asking to input credentials [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”) | Out-Null [Windows.Forms.MessageBox]::Show("Please Supply Your vCenter Server Credentials in the next Window”,0, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information) $vccred = (Get-Credential) # Connect to vCenter Server Connect-VIServer -Server $vc -Credential $vccred Write-Output "Datastore,Host,VMName,FQDN,Power,OS,IP,vCenter Server" | Out-File $outfile -Force # -Force will overwrite any existing file Get-Datastore -Server $vc | Sort-Object {$_.name} | % { $datastore = $_.name Get-VM -Datastore $datastore | select name,powerstate | % { $name = $_.name $power = $_.powerstate $vmhost = $_.vmhost Get-VMGuest $name | select hostname,osfullname,ipaddress | % { $hostname = $_.hostname $os = $_.osfullname $ip = $_.IPaddress Write-Output "$datastore,$vmhost,$name,$hostname,$power,$os,$ip,$vc" | Out-File $outfile -Append }}}

Powershell VMWare Inventory
Posted in VMWare and tagged enterprise-it, inventory, posh, power os, powercli, powershell, scripts, vm, vm inventory, vms version, vmware, vsphere.