modules/Utilities/private/Confirm-DiskSpace.ps1
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. function Confirm-DiskSpace { [CmdletBinding()] param ( [Parameter(Mandatory = $false, ParameterSetName = 'GB')] [Parameter(Mandatory = $false, ParameterSetName = 'MB')] [System.Char]$DriveLetter, [Parameter(Mandatory = $true, ParameterSetName = 'GB')] $MinimumGB, [Parameter(Mandatory = $true, ParameterSetName = 'MB')] $MinimumMB ) try { $drive = Get-PSDrive $DriveLetter -ErrorAction Stop if ($null -eq $drive) { throw New-Object System.NullReferenceException("Unable to retrieve PSDrive information") } $freeSpace = Format-ByteSize -Bytes $drive.Free switch ($PSCmdlet.ParameterSetName) { 'GB' { "Required: {0} GB | Available: {1} GB" -f ([float]$MinimumGB).ToString(), $freeSpace.GB | Trace-Output if ([float]$freeSpace.GB -gt [float]$MinimumGB) { return $true } } 'MB' { "Required: {0} MB | Available: {1} MB" -f ([float]$MinimumMB).ToString(), $freeSpace.MB | Trace-Output if ([float]$freeSpace.MB -gt [float]$MinimumMB) { return $true } } } return $false } catch { "{0}`n{1}" -f $_.Exception, $_.ScriptStackTrace | Trace-Output -Level:Error } } |