---
updatedAt: 2025-08-14T17:30:50.000Z
agentTools:
  siteIndex: https://developer.n-able.com/llms.txt
  projectIndex: https://developer.n-able.com/n-sight/llms.txt
---

# Volume Check

```powershell PowerShell
# ----- Legal: ----
# Sample scripts are not supported under any N-able support program or service.
# The sample scripts are provided AS IS without warranty of any kind.
# N-able expressly disclaims all implied warranties including, warranties
# of merchantability or of fitness for a particular purpose.
# In no event shall N-able or any other party be liable for damages arising
# out of the use of or inability to use the sample scripts.
# -----------------------------------------------------------

# Script updated Dec 2020, Steve Knight.
# V1.0 Get Volume info
# V1.1 Cope with old PS versions without get-volume
# V1.2 July 2021 - add error notification if status isn't Healthy or OK
#
# -DriveLetters E = returns info for drive E only including label and free space
# -DriveLetters CDE = returns info for drive CDE only including label and free space
# -DriveLabel XXXX = returns info for drive with that label only, can use wildcards
# -CheckFreeGb = Error if less than this many Gb free
# -CheckFreePercent = Error if less than this %age free
# -ErrorMissing = returns error if the drive specified is not present
#
# Otherwise all drive details are returned


param ([string]$DriveLetters='',[string]$DriveLabel='',[int]$CheckFreeGb=0,[int]$CheckFreePercent=0,[switch]$ErrorMissing=$False)

# Use WMI call instead of get-volume which doesn't exist on PS
$UseWMI=$False
if ((get-host).version.major -le 4) {$UseWMI=$True}

$ErrorFound=0
$Info=''
$Errors=''


if ($DriveLetters -eq '' -And $DriveLabel -eq '') {
    if ($UseWMI) {
        $Volumes=Get-wmiobject Win32_volume | where-object {$_.DriveLetter -ne $Null -and $_.DriveType -ne 5 } | Select DriveLetter, Label, Freespace, Capacity, Status, StatusInfo | sort-object -Property DriveLetter
    } ELSE {
        $Volumes=Get-Volume | sort-object -Property DriveLetter
        if ($Volumes.HealthStatus -ne "Healthy") {
            $Errors+="VOLUME HEALTH ISSUE FOUND`r`n`r`n"
            $ErrorFound=1
        }
    }
} ELSE {
    if ($DriveLetters -ne '') {
        try {
            if ($UseWMI) {
                $Volumes=Get-wmiobject Win32_volume | where-object {$_.DriveLetter -like "$DriveLetters*" -and $_.DriveType -ne 5 } | Select DriveLetter, Label, Freespace, Capacity, Status, StatusInfo | sort-object -Property DriveLetter
            } ELSE {
                $Volumes=get-volume $DriveLetters -ErrorAction SilentlyContinue | sort-object -Property DriveLetter
                if ($Volumes.HealthStatus -ne "Healthy") {
                    $Errors+="VOLUME HEALTH ISSUE FOUND`r`n`r`n"
                    $ErrorFound=1
                }
            }

            if ($Volumes -eq $Null) {
                $Errors+="VOLUME $DriveLetters NOT FOUND`r`n`r`n"
                $ErrorFound=1
            }
        }
        catch {
            $Errors+="VOLUME $DriveLetters NOT FOUND`r`n`r`n"
            $ErrorFound=1
        }
        
    } ELSE {

        if ($UseWMI) {
            $Volumes=Get-wmiobject Win32_volume | where-object {$_.Label -like "$DriveLabel" -and $_.DriveType -ne 5 } | Select DriveLetter, Label, Freespace, Capacity, Status, StatusInfo | sort-object -Property DriveLetter
        } ELSE {
            $Volumes=get-volume -FileSystemLabel $DriveLabel | sort-object -Property DriveLetter
        }

        if ($Volumes -eq $Null) {
            $Errors+="VOLUME $DriveLabel NOT FOUND`r`n`r`n"
            $ErrorFound=1
        }
    }
}


if ($UseWMI) {
    foreach ($V in $Volumes) {
      if ($V.Driveletter -ne $Null -and $V.DriveType -ne 5) {
         $Info+="$($V.DriveLetter) [$($V.Label)] $([math]::Round($V.Freespace/1GB,2)) free / $([math]::Round($V.Capacity/1GB,2)) Gb $($V.Status) $($V.StatusInfo)`r`n"
         if ($CheckFreePercent -gt 0) {
            $PercentageFree=$([math]::Round($V.Freespace/$V.Capacity*100,1))
            if ($PercentageFree -lt $CheckFreePercent) {
                $Errors+="ERROR - $($V.DriveLetter) [$($V.Label)] $PercentageFree %`r`n"
                $ErrorFound=1
            }
        }
        if ($CheckFreeGb -gt 0) {
            $FreeSpace=$([math]::Round($V.Freespace/1GB,2))
            if ($FreeSpace -lt $CheckFreeGB) {
               $Errors+="ERROR - $($V.DriveLetter) [$($V.Label)] $FreeSpace Gb`r`n"
               $ErrorFound=1
            }
        }
      }
    }
} ELSE {
    foreach ($V in $Volumes) {
      if ($V.Driveletter -ne $Null -and $V.DriveType -ne "CD-ROM") {
         $Info+="$($V.DriveLetter): [$($V.FileSystemLabel)] $([math]::Round($V.SizeRemaining/1GB,2)) free / $([math]::Round($V.Size/1GB,2)) Gb $($V.HealthStatus) $($V.OperationalStatus)`r`n"
         if ($CheckFreePercent -gt 0) {
            $PercentageFree=$([math]::Round($V.SizeRemaining/$V.Size*100,1))
            if ($PercentageFree -lt $CheckFreePercent) {
                $Errors+="ERROR - $($V.DriveLetter) [$($V.FileSystemLabel)] $PercentageFree %`r`n"
                $ErrorFound=1
            }
        }
        if ($CheckFreeGb -gt 0) {
            $FreeSpace=$([math]::Round($V.SizeRemaining/1GB,2))
            if ($FreeSpace -lt $CheckFreeGB) {
                $Errors+="ERROR - $($V.DriveLetter) [$($V.FileSystemLabel)] $FreeSpace Gb`r`n"
                $ErrorFound=1
            }
        }


      }
    }
}

Write-Host $Errors
Write-Host $Info

If ($ErrorMissing -and $ErrorFound -eq 1) {
    exit 1
} ELSE {
    exit 0
}



```

```json Response Example
{"success":true}
```

# SCRIPT