You can use this command for see space of all disks.
Write-Host "Host: $env:COMPUTERNAME ($(Get-Date -Format โMM/dd/yyyyโ)) " -foregroundcolor "green"
Get-WMIObject -Class Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3} `
| Select-Object @{n="Unit";e={($_.Name)}},
@{n="Label";e={($_.VolumeName)}},
@{n='Size (GB)';e={"{0:n2}" -f ($_.size/1gb)}},
@{n='Free (GB)';e={"{0:n2}" -f ($_.freespace/1gb)}},
@{n='% Free';e={"{0:n2}" -f ($_.freespace/$_.size*100)}} `
Note: for remote host use Enter-PSSession <ComputerName>
/ Exit-PSSession
and run script.
or for many hosts can use invoke command adding parameter COMPUTER_NAME .
$machines = @(
'COMPUTER_NAME_1',
'COMPUTER_NAME_2'
)
foreach ($machine in $machines) {
Invoke-Command -ComputerName $machine -ScriptBlock {
Write-Host "Host: $env:COMPUTERNAME ($(Get-Date -Format โMM/dd/yyyyโ)) " -foregroundcolor "green"
(Get-WMIObject -Class Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3} `
| Select-Object @{n="Unit";e={($_.Name)}},
@{n="Label";e={($_.VolumeName)}},
@{n='Size (GB)';e={"{0:n2}" -f ($_.size/1gb)}},
@{n='Free (GB)';e={"{0:n2}" -f ($_.freespace/1gb)}},
@{n='% Free';e={"{0:n2}" -f ($_.freespace/$_.size*100)}}
)
}
}
Top comments (0)