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?