Get Disk space of multiple remote machines

This topic contains 3 replies, has 3 voices, and was last updated by  Frank Tucker 7 months, 1 week ago.

  • Author
    Posts
  • #66352

    Jay V
    Participant

    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?

  • #66355

    Sam Boutros
    Participant
  • #66378

    Jay V
    Participant

    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%

  • #66526

    Frank Tucker
    Participant

    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

You must be logged in to reply to this topic.