Skip to content

Commit a91c893

Browse files
committed
Fixed Compress-Archive so that it can compress to a custom PSDrive
1 parent 560f585 commit a91c893

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ function Compress-Archive
7979
)
8080

8181
BEGIN
82-
{
82+
{
83+
# Ensure the destination path is in a non-PS-specific format
84+
$DestinationPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($DestinationPath)
85+
8386
$inputPaths = @()
8487
$destinationParentDir = [system.IO.Path]::GetDirectoryName($DestinationPath)
8588
if($null -eq $destinationParentDir)

Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,19 @@ Describe "Test suite for Microsoft.PowerShell.Archive module" -Tags "BVT" {
685685
try { Expand-Archive -Path $sourcePath -DestinationPath $destinationPath; throw "Expand-Archive did NOT throw expected error" }
686686
catch { $_.FullyQualifiedErrorId | Should Be "InvalidDirectoryPath,Expand-Archive" }
687687
}
688+
689+
It "Validate that you can compress an archive to a custom PSDrive using the Compress-Archive cmdlet" {
690+
$sourcePath = "$TestDrive\SourceDir\ChildDir-1\Sample-3.txt"
691+
$destinationDriveName = 'CompressArchivePesterTest'
692+
$destinationDrive = New-PSDrive -Name $destinationDriveName -PSProvider FileSystem -Root $TestDrive -Scope Global
693+
$destinationPath = "${destinationDriveName}:\CompressToPSDrive.zip"
694+
try {
695+
Compress-Archive -Path $sourcePath -DestinationPath $destinationPath
696+
$destinationPath | Should Exist
697+
} finally {
698+
Remove-PSDrive -LiteralName $destinationDriveName
699+
}
700+
}
688701
}
689702

690703
Context "Expand-Archive - functional test cases" {

0 commit comments

Comments
 (0)