30 C
Dubai
Wednesday, October 9, 2024

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
Award-winning Technology Leader with a wealth of experience running large teams and diversified industry exposure in cloud computing. From shipping lines to rolling stocks.In-depth expertise in driving cloud adoption strategies and modernizing systems to cloud native. Specialized in Microsoft Cloud, DevOps, and Microsoft 365 Stack and conducted numerous successful projects worldwide. Also, Acting as a Technical Advisor for various start-ups.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

× How can I help you?