diff --git a/src/Microsoft.PowerShell.Security/security/CatalogCommands.cs b/src/Microsoft.PowerShell.Security/security/CatalogCommands.cs index 07f2dc9015..722a8b0707 100644 --- a/src/Microsoft.PowerShell.Security/security/CatalogCommands.cs +++ b/src/Microsoft.PowerShell.Security/security/CatalogCommands.cs @@ -95,7 +95,7 @@ namespace Microsoft.PowerShell.Commands { foreach (PathInfo tempPath in SessionState.Path.GetResolvedPSPathFromPSPath(p)) { - if (ShouldProcess(tempPath.ProviderPath)) + if (ShouldProcess("Including path " + tempPath.ProviderPath, "", "")) { paths.Add(tempPath.ProviderPath); } @@ -103,17 +103,16 @@ namespace Microsoft.PowerShell.Commands } } - // We add 'paths.Count > 0' to support 'ShouldProcess()' - if (paths.Count > 0 ) + string drive = null; + + // resolve catalog destination Path + if (!SessionState.Path.IsPSAbsolute(catalogFilePath, out drive) && !System.IO.Path.IsPathRooted(catalogFilePath)) { - string drive = null; - - // resolve catalog destination Path - if (!SessionState.Path.IsPSAbsolute(catalogFilePath, out drive) && !System.IO.Path.IsPathRooted(catalogFilePath)) - { - catalogFilePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(catalogFilePath); - } + catalogFilePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(catalogFilePath); + } + if (ShouldProcess(catalogFilePath)) + { PerformAction(paths, catalogFilePath); } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Security/FileCatalog.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Security/FileCatalog.Tests.ps1 index 85e4c9c871..712310c8e5 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Security/FileCatalog.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Security/FileCatalog.Tests.ps1 @@ -233,11 +233,14 @@ Describe "Test suite for NewFileCatalogAndTestFileCatalogCmdlets" -Tags "CI" { try { copy-item "$testDataPath\UserConfigProv" $env:temp -Recurse -ErrorAction SilentlyContinue - $null = New-FileCatalog -Path $env:temp\UserConfigProv\ -CatalogFilePath $catalogPath -CatalogVersion 1.0 - $result = Test-FileCatalog -Path $env:temp\UserConfigProv\ -CatalogFilePath $catalogPath + Push-Location "$env:TEMP\UserConfigProv" + # When -Path is not specified, it should use current directory + $null = New-FileCatalog -CatalogFilePath $catalogPath -CatalogVersion 1.0 + $result = Test-FileCatalog -CatalogFilePath $catalogPath } finally { + Pop-Location Remove-Item "$catalogPath" -Force -ErrorAction SilentlyContinue Remove-Item "$env:temp\UserConfigProv\" -Force -ErrorAction SilentlyContinue -Recurse }