Check remotely hard disk size

foreach ($servername in $servernames) {
    $temp = Test-NetConnection -computername $servername -port 5985 -InformationLevel quiet
    write-host “___________________________________________________”
    if ( $temp -eq ‘true’){
        $drive = invoke-command -computername $servername -scriptblock { get-psdrive c }
        $used_size = $drive.used
        $free_size = $drive.Free
        write-host $servername “Drive C [USED]:” ($used_size / 1GB)
    if (($free_size / 1GB) -le 10){
        write-host $servername “Drive C [FREE]:” ($free_size / 1GB) -BackgroundColor red }
    else{
        write-host $servername “Drive C [FREE]:” ($free_size / 1GB)}
        write-host “___________________________________________________”
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *