mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Merge pull request #1623 from PowerShell/jimtru/PSDriveFreeSpaceFix
Get-PSDrive should report proper free space on all platforms
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user