Get Disk space of multiple remote machines

Hi all - I’m trying to create a script that will give me the diskspace of multiple remote servers and display to screen (will build functionality to this later). At present I cna get the script to cycle through a text file and provide out but it’s all data from the first server in the list, See code and output below.

$name = get-content “c:\scripts\servers.txt”

foreach ($SERVER in $name)
{Write-host “information for $SERVER”
Get-CimInstance -ClassName Win32_LogicalDisk -Filter ‘DriveType=3’|

Select-Object Deviceid,
@{N=‘Size(GB)’; E={[math]::Round($.Size / 1GB, 2)}},
@{N=‘FreeSpace(GB)’; E={[math]::Round($
.FreeSpace / 1GB, 2)}},
@{N=‘PercentFree’; E={[math]::Round(($.FreeSpace / $.Size) * 100, 2)}}
}

OUTPUT

information for server1

Deviceid Size(GB) FreeSpace(GB) PercentFree


C: 39.66 28.29 71.35
D: 40 39.46 98.66
E: 75 55.85 74.47
information for server2
C: 39.66 28.29 71.35
D: 40 39.46 98.66
E: 75 55.85 74.47
information for server3
C: 39.66 28.29 71.35
D: 40 39.46 98.66
E: 75 55.85 74.47

Can anyone point me in the right direction?

Try this function: Powershell script to get disk information including block size

So I can get the information I need using the below however I can’t get the computer name between the data so I tell what relates to each server.

C:\Windows\system32> Get-WmiObject Win32_logicaldisk -ComputerName server1, server2, server3 `
| Format-Table DeviceID, MediaType, `
@{Name=“Size(GB)”;Expression={[decimal](“{0:N0}” -f($.size/1gb))}}, `
@{Name=“Free Space(GB)”;Expression={[decimal](“{0:N0}” -f($
.freespace/1gb))}}, `
@{Name=“Free (%)”;Expression={“{0,6:P0}” -f(($.freespace/1gb) / ($.size/1gb))}} `
-AutoSize

DeviceID MediaType Size(GB) Free Space(GB) Free (%)


C: 12 60 2 4%
D: 12 40 34 86%
E: 12 60 46 76%
F: 11 1 0 0%
A: 5 0 0
C: 12 60 8 13%
D: 12 40 26 65%
E: 12 60 56 94%
F: 11 3 0 0%
C: 12 60 1 2%
D: 12 40 17 43%
E: 12 60 23 38%
F: 11 1 0 0%

Answering from phone, otherwise I would give code. The advance toolmaking book from Mr. Jones has some great examples for what y are doing. My function find-smbshare on the powershell gallery may also help.

I think your 1st code is just missing the -computername param with get-ciminstance so it loops through each $server
Or
Create a new-cimsession pipes to each instance