$report = Get-VM | ForEach-Object { $vm = $_ if ($vm.Generation -eq "2") { $firmware = Get-VMFirmware -VM $vm $security = Get-VMSecurity -VM $vm $secureboot = $firmware.SecureBoot $tpmenabled = $security.TpmEnabled $osType = if ($firmware.SecureBootTemplate -eq "MicrosoftWindows") { "Windows" } else { "Linux" } } else { $secureboot = $null $tpmenabled = $null $osType = $null } $disks = @(Get-VMHardDiskDrive -VM $vm) $dvds = @(Get-VMDVDDrive -VM $vm) $nics = @(Get-VMNetworkAdapter -VM $vm) $osDisk = $null $controllerType = switch ($vm.Generation) { 2 { 'SCSI' } 1 { 'IDE' } default { $null } } if ($null -ne $controllerType) { $osDisk = $disks | Where-Object { $_.ControllerType -eq $controllerType } | Sort-Object ControllerNumber, ControllerLocation | Select-Object -First 1 } $osDiskSizeGB = if ($osDisk.Path) { try { [math]::Round((Get-VHD -Path $osDisk.Path -ErrorAction Stop).Size / 1GB, 1) } catch { $null } } else { "(nodisk)" } [pscustomobject]@{ VMName = $vm.Name Generation = $vm.Generation ConfigPath = $vm.ConfigurationLocation VMId = $vm.VMId ## Firmware ## Security SecureBoot = $secureboot TPMEnabled = $tpmenabled OSType = $ostype ## Processor vCPUs = $vm.ProcessorCount NestedVirt = (Get-VMProcessor -VM $vm).ExposeVirtualizationExtensions ## Memory # MemoryAssigned = $vm.MemoryAssigned DynamicMemory = $vm.DynamicMemoryEnabled RAMStartupGB = [math]::Round($vm.MemoryStartup / 1GB, 1) RAMMinimumGB = [math]::Round($vm.MemoryMinimum / 1GB, 1) RAMMaximumGB = [math]::Round($vm.MemoryMaximum / 1GB, 1) ## HardDrives OSDiskPath = if ($null -ne $osDisk) { $osDisk.Path } else { "(nodisk)" } OSDiskGB = $osDiskSizeGB #DataDisks = [math]::Max($disks.Count - 1, 0) DataDisks = $disks.Count - $(if ($null -ne $osDisk) { 1 } else { 0 }) ## DVDDrives DVDs = $dvds.Count ## NetoworkAdapters NICs = $nics.Count Version = $vm.Version CreationTime = $vm.CreationTime # isClustered = $vm.isClustered } } $report