Merge pull request #1623 from PowerShell/jimtru/PSDriveFreeSpaceFix

Get-PSDrive should report proper free space on all platforms
This commit is contained in:
Jason Shirk
2016-08-03 14:11:28 -07:00
committed by GitHub
2 changed files with 11 additions and 6 deletions
@@ -52,18 +52,15 @@ namespace System.Management.Automation.Runspaces
if($this.Provider.ImplementingType -eq
[Microsoft.PowerShell.Commands.FileSystemProvider])
{
$driveRoot = ([System.IO.DirectoryInfo] $this.Root).Name.Replace('\','')
$drive = Get-CimInstance Win32_LogicalDisk -Filter ""DeviceId='$driveRoot'""
$drive.Size - $drive.FreeSpace
$driveInfo = [System.IO.DriveInfo]::New($this.Root)
if ( $driveInfo.IsReady ) { $driveInfo.TotalSize - $driveInfo.AvailableFreeSpace }
}"), null));
td4.Members.Add("Free",
new ScriptPropertyData(@"Free", GetScriptBlock(@"## Ensure that this is a FileSystem drive
if($this.Provider.ImplementingType -eq
[Microsoft.PowerShell.Commands.FileSystemProvider])
{
$driveRoot = ([System.IO.DirectoryInfo] $this.Root).Root.Name.Replace('\','')
$drive = Get-CimInstance Win32_LogicalDisk -Filter ""DeviceId='$driveRoot'""
$drive.FreeSpace
[System.IO.DriveInfo]::New($this.Root).AvailableFreeSpace
}"), null));
yield return td4;
@@ -44,4 +44,12 @@ Describe "Get-PSDrive" -Tags "CI" {
!(Get-PSDrive fake -ErrorAction SilentlyContinue) | Should Be $True
Get-PSDrive fake -ErrorAction SilentlyContinue | Should BeNullOrEmpty
}
It "Should be able to determine the amount of free space of a drive" {
$dInfo = Get-PSDrive TESTDRIVE
$dInfo.Free -ge 0 | Should be $true
}
It "Should be able to determine the amount of Used space of a drive" {
$dInfo = Get-PSDrive TESTDRIVE
$dInfo.Used -ge 0 | Should be $true
}
}