使用PowerShell脚本(Get-VM)在VMM中使用(Get-SCVirtualMachine)

时间:2017-11-29 10:27:45

标签: powershell system-center

我正在尝试获取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) 

任何想法?

0 个答案:

没有答案