Get Free Disk Space%, Disk Size, Free Space from Multiple Remote VM

I’m pretty new to PS, and I need your help. With my script I’m trying to get what the title says. I am getting the data to return (not perfectly), but I want to do it for each machine. I’m not adhered to any of this except the required output. I imagine that there will be a cleaner way to do this. I really appreciate your help!

Here is my current output: `Name Value ‘


‘Freespace {26078019584, 27096956928, 25799286784, 26667339776…}’
‘Size {64971862016, 64971862016, 64971862016, 64971862016…} ‘
‘FreeDisk% {40, 42, 40, 41…} ‘`

I’m confused how to get it per machine and also display the machine name.

Here is my script:

$VM = Get-VM -Location Sandbox -Name “VMName*” | Select -ExpandProperty Name | ForEach-Object {“$_.add.FQDN”} | Sort-Object param($VM) $Exp = gwmi Win32_LogicalDisk -ComputerName $VM -Credential $cred -Filter “DeviceID=C:” @{“FreeDisk%”=$Exp | ForEach { [Math]::Round(($.FreeSpace / 1GB)/($.Size/ 1GB) * 100) }; Freespace=Exp | Select -ExpandProperty Freespace; Size=$Exp | Select -ExpandProperty Size }

Multiple edits: syntax noob

submitted by /u/sixfingerdiscount
[link] [comments]

Leave a Reply