0

Am new to scripting kindly help me write a script that will connect to VMM and get details such as below.

Name                 : ABC Machine
CPUCount             : 8
Memory               : 8192
DynamicMemoryEnabled : False

VHDType        : DynamicallyExpanding
MaximumSize    : 214748364800
Size           : 4194304
Location       : C:\ClusterStorage\Volume3\CRB\CRB Test Machine_disk_1.vhdx
Classification : Silver

VHDType        : DynamicallyExpanding
MaximumSize    : 4748364800
Size           : 41304
Location       : C:\ClusterStorage\Volume2\CRB\CRB Test Machine_disk_2.vhdx
Classification : Silver

I have been able to get individual commands to get the info however I am not able to make a script that will do it for all VMs and convert disk sizes to GB

My working commands are

Get-SCVirtualMachine -Name "ABC Machine" | select Name, CPUCount, Memory, DynamicMemoryEnabled | fl
$DiskINfo = Get-SCVirtualDiskDrive -VMMServer "abc.abcgroupcloud.com" -VM "ABC Machine"
$DiskINfo.VirtualHardDisk | select VHDType, MaximumSize, Size, Location, Classification

2 Answers2

0

1- create an array with all the VM names (or read it from a file with get-content)
2- use a foreach loop to excecute you script over all these VM
3- use a calulated property to display the size in Gb

$computers=@("ABC machine","XYZ machine")

$computers | foreach-object {
    Get-SCVirtualMachine -Name $_ | select Name, CPUCount, Memory, DynamicMemoryEnabled | fl
    $DiskINfo = Get-SCVirtualDiskDrive -VMMServer "abc.abcgroupcloud.com" -VM $_
    $DiskINfo.VirtualHardDisk | select VHDType, MaximumSize, @{Name="Size in Gb";Expression={$($_.size)Mb / 1Gb}}, Location, Classification
}
Loïc MICHEL
  • 24,935
  • 9
  • 74
  • 103
0

Old question, but just to add some info. This will get all the Virtual Machines in your host group in VMM, after entering the correct host group name.

$VMs will be the array, which will contain all the details you are after.

$hg = Get-SCVMHostGroup -Name "My Hostgroup Name"

$hosts = Get-SCVMHost -VMHostGroup $hg

$VMs = $null

ForEach ($h in $hosts) 
{
    $VMs += Get-SCVirtualMachine -VMHost $h
}
Justin Cooksey
  • 311
  • 2
  • 5