# $cs.Sys_GetFreeDiskSpace

> Returns the amount of free disk space, in megabytes, on the specified drive. Returns -1 if the drive isn't ready or can't be found.

Source: https://docs.capaone.com/capainstaller/powerpacks/cs-sys-getfreediskspace/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

### Description

Returns the amount of free disk space, in megabytes, on the specified drive. Returns `-1` if the drive isn't ready or can't be found.

### Syntax

$cs.Sys_GetFreeDiskSpace(string drive = "C:")

### Parameters

#### drive (String)

Drive to get free disk space from. Defaults to `"C:"`.

### Return value

Double. Free disk space on the drive in MB, or `-1` if the drive isn't ready or can't be found.

### Example

**PowerShell**

Log free space on the system drive for diagnostics before a large extraction:

```powershell
$freeDiskspaceMB = $cs.Sys_GetFreeDiskSpace("C:")
$cs.Job_WriteLog("Free disk space on C: is $freeDiskspaceMB MB")
```

Check a non-system data drive before copying a large installation kit to it:

```powershell
$freeDiskspaceMB = $cs.Sys_GetFreeDiskSpace("D:")
if ($freeDiskspaceMB -eq -1)
{
  throw "Drive D: was not found"
}
$cs.Job_WriteLog("Free disk space on D: is $freeDiskspaceMB MB")
```

Compare free space before and after an installation step to see how much space it consumed:

```powershell
$freeBeforeMB = $cs.Sys_GetFreeDiskSpace($global:gsSysDrive)
# ... run installer ...
$freeAfterMB = $cs.Sys_GetFreeDiskSpace($global:gsSysDrive)
$cs.Job_WriteLog("Install consumed $([math]::Round($freeBeforeMB - $freeAfterMB)) MB on $($global:gsSysDrive)")
```

### Related functions

[$cs.Sys_IsMinimumRequiredDiskspaceAvailable](/capainstaller/powerpacks/cs-sys-isminimumrequireddiskspaceavailable/)
