Created
June 27, 2023 19:13
-
-
Save bharkr/8ee3bb6b6f24bc8ea6a6b80a0de359b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -modules VMware.PowerCLI | |
$vcenterServer = '' | |
Connect-VIServer $vCenterServer | |
$virtGuests = Get-VM | Where-Object { $_.PowerState -eq 'PoweredOn' } | |
$vmInfoReport = @() | |
foreach ($guest in $virtGuests) { | |
$guestObj = [PSCustomObject]@{ | |
Name = $guest.Name | |
NumCpu = $guest.NumCpu | |
MemoryMB = $guest.MemoryMB | |
ResourcePool = $guest.ResourcePool | |
OS = ($guest.Guest).OSFullName | |
} | |
$nics = $guest | Get-NetworkAdapter | |
foreach ($nic in $nics) { | |
$guestObj | Add-Member -MemberType NoteProperty -Name "$($nic.Name) MAC" -Value $nic.MacAddress | |
} | |
if (!($guest.Guest.Nics.IPAddress -like 'fe*')) { | |
$guestObj | Add-Member -MemberType NoteProperty -Name "IPAddress" -Value ($guest.Guest).Nics.IPAddress | |
} | |
$disks = $guest | Get-HardDisk | |
foreach ($disk in $disks) { | |
$guestObj | Add-Member -MemberType NoteProperty -Name "$($disk.Name) Size(GB)" -Value $disk.CapacityGB | |
$guestObj | Add-Member -MemberType NoteProperty -Name "$($disk.Name) Path" -Value $disk.Filename | |
} | |
$vmInfoReport += $guestObj | |
} | |
$headers = $vmInfoReport | ForEach-Object { $_.PSObject.Properties.Name } | Select-Object -Unique | |
$vmInfoReport | ForEach-Object { | |
$_ | Select-Object -Property $headers | |
} | Export-Csv /mnt/c/Users/brian/test.csv -Append | |
Disconnect-VIServer -Server $vcenterServer -Confirm:$false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment