DEV Community

redhcp
redhcp

Posted on • Edited on

Powershell % disk space

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)}} `
Enter fullscreen mode Exit fullscreen mode

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)}}
       )  
    }
}
Enter fullscreen mode Exit fullscreen mode

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs