我正在尝试获取 PowerShell 脚本,用于获取有关 Hyper-V 中已安装 VM 的信息,以便在 System Center VMM 中工作。这是在本地安装的 Hyper-V 安装中运行的代码:
$Results = @()
foreach ($VM in (Get-VM))
{
$Row = "" | Select 'Name','CPUs','Dynamischer Arbeitsspeicher','RAM Maximum (in MB)','RAM Minimum (in MB)','Groesse der VHD (in GB)'
$Row.'Name' = $VM.Name
$Row.'CPUs' = $VM.ProcessorCount
$Row.'Dynamischer Arbeitsspeicher' = $VM.DynamicMemoryEnabled
$Row.'RAM Maximum (in MB)' = $VM.MemoryMaximum/1MB
$Row.'RAM Minimum (in MB)' = $VM.MemoryMinimum/1MB
$Total=0; ($VM.VMId | Get-VHD | %{$Total += ($_.FileSize/1GB)})
$Row.'Groesse der VHD (in GB)' = [math]::Round($Total)
$Results += $Row
}
$Results | Export-Csv c:\vm.csv #-Delimiter ';' -NoTypeInformation
Import-Csv -Path c:\vm.csv | Out-GridView
我尝试使用 VMM 所需的命令来调整此代码。除了显示尺寸所需的两条线外,一切正常。这是完整的代码:
$Results = @()
foreach ($VM in (Get-SCVirtualMachine))
{
$Row = "" | Select 'Name','CPUs','Dynamischer Arbeitsspeicher','RAM','Dynamischer RAM Maximum (in MB)','Dynamischer RAM Minimum (in MB)','Groesse der VHD (in GB)'
$Row.'Name' = $VM.Name
$Row.'CPUs' = $VM.CPUCount
$Row.'Dynamischer Arbeitsspeicher' = $VM.DynamicMemoryEnabled
if($VM.DynamicMemoryEnabled) {
$Row.'Dynamischer RAM Maximum (in MB)' = $VM.DynamicMemoryMaximumMB
$Row.'Dynamischer RAM Minimum (in MB)' = $VM.DynamicMemoryMinimumMB
}
else{
$Row.'RAM' = $VM.Memory
}
$Total=0; ($VM.VMId | Get-SCVirtualHardDisk | %{$Total += ($_.MaximumSize/1GB)})
$Row.'Groesse der VHD (in GB)' = [math]::Round($Total)
$Results += $Row
}
$Results | Export-Csv c:\vm.csv #-Delimiter ';' -NoTypeInformation
Import-Csv -Path c:\vm.csv | Out-GridView
以下是导致错误的两行:
$Total=0; ($VM.VMId | Get-SCVirtualHardDisk | %{$Total += ($_.MaximumSize/1GB)})
$Row.'Groesse der VHD (in GB)' = [math]::Round($Total)
错误说:
Get-SCVirtualHardDisk : VMM is unable to connect to the VMM management server XXX because the specified computer name could
not be resolved. (Error ID: 1601)
有任何想法吗?