diff --git a/src/System.Management.Automation/engine/Types_Ps1Xml.generated.cs b/src/System.Management.Automation/engine/Types_Ps1Xml.generated.cs index 12335c6cf..9e4e330af 100644 --- a/src/System.Management.Automation/engine/Types_Ps1Xml.generated.cs +++ b/src/System.Management.Automation/engine/Types_Ps1Xml.generated.cs @@ -52,29 +52,15 @@ namespace System.Management.Automation.Runspaces if($this.Provider.ImplementingType -eq [Microsoft.PowerShell.Commands.FileSystemProvider]) { - if ( ! $IsWindows ) { - $driveInfo = ([System.IO.DriveInfo]::GetDrives()|where-object {$_.Name -eq $this.Root}|Select-Object -first 1) - $driveInfo.TotalSize - $driveInfo.AvailableFreeSpace - } - else { - $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]) { - if ( ! $IsWindows ) { - ([System.IO.DriveInfo]::GetDrives()|where-object {$_.Name -eq $this.Root}|Select-Object -first 1).AvailableFreeSpace - } - else { - $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; diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSDrive.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSDrive.Tests.ps1 index 3fe0b272c..75c9d2ac0 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSDrive.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSDrive.Tests.ps1 @@ -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 + } }