38 C
Dubai
Wednesday, August 17, 2022
spot_img

Vcenter Virtual Machines Report using a simple PowerCLI Script

Have created a simple CLI Script to Dump Virtual machine info to a CSV file. Have Skipped Cpu,RAM information.

CSV would Contain below Columns,

VMName,VMHostName,VMIPAddress,VMInstalledOS,PowerState,HostServer,HostCluster,Notes

Step 1 :

Open PowerCLI – VMware.

Connect-VIServer -Server vcenter.domain.com -Protocol https -User "care\manoharan" –Password P@330eod 

Step 2 :

Example —

 PowerCLI F:\Scripts> .\VmwareExport.ps1 

CSV saves to Scripts Folder. In above example

# Save as ps1


Write-host "Saving CSV Variable"
$ExportPath = "Vms.csv"
Write-host "Saved CSV Variable"
Write-host "Saving ALL VMs"
$VMs = Get-VM
Write-host "Saved ALL VMs"
$VCenter = @()
Write-host "Entering Loop"
foreach ($vm in $VMs)
{
Write-host "Collecting $VM info"
$HostServer = $vm.host.Name
$VMSysInfo = Get-VMGuest -VM $VM
$MyObject = New-Object PSObject -Property @{
VMName = $VM.name
VMHostName = $VMSysInfo.HostName
VMIP = $VMSysInfo.IPAddress
VMInstalledOS = $VMSysInfo.OSFullName
PowerState = $vm.powerstate
HostServer = $HostServer
HostCluster = (Get-Cluster -VMHost $HostServer).Name
Notes = $vm.notes
}
$VCenter += $MyObject
}
$VCenter |
Select VMName,
VMHostName,
@{N='VMIPAddress';E={$_.VMIP -join '; '}},
VMInstalledOS,
PowerState,
HostServer,
HostCluster,
Notes |
Export-Csv $ExportPath -NoTypeInformation

Satheshwaran Manoharan
Satheshwaran Manoharanhttps://www.azure365pro.com
Specialized in Microsoft Azure - Office 365 / Microsoft Exchange; conducted numerous projects worldwide in designing, supporting, and implementing messaging and virtualization infrastructure for medium-sized and large enterprises. Further, I am a Cloud Architect and Technical Advisor for various start-ups.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here