Adpating a PowerShell Script (Get-VM) for the use in VMM (Get-SCVirtualMachine)

1k Views Asked by At

I'm trying to get a PowerShell Script, for obtaining Informations about the installed VMs in Hyper-V, to work in System Center VMM. Here is the code which is working in a locally installed Hyper-V installation:

$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

I tried to adapt this code with the needed commands for VMM. Everything works except for the two lines which are needed for displaying the size. Here is the full code:

$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    

Here are the two lines which are causing errors:

$Total=0; ($VM.VMId | Get-SCVirtualHardDisk | %{$Total += ($_.MaximumSize/1GB)})
    $Row.'Groesse der VHD (in GB)' = [math]::Round($Total)

The error says:

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) 

Any Ideas?

0

There are 0 best solutions below