1

I am using a PSDrive for Compress-Archive but I come across this error:

Compress-Archive : The path 'Z:\' either does not exist or is not a valid file system path.
At C:\Users\user\somefolder\script.ps1:34 char:5
+     Compress-Archive -Path ($ZDrive + $fileName + $csvExt) -Destinati ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Z:\:String) [Compress-Archive], InvalidOperationException
    + FullyQualifiedErrorId : ArchiveCmdletPathNotFound,Compress-Archive

The PSDrive code and codes at line 33 and 34 are these:

New-PSDrive -Name "Z" -Root $OutputDirectoryPath -PSProvider FileSystem;
$ZDrive = "Z:\";
query($CustomQuery) | Export-Csv -Path ($ZDrive + $fileName + $csvExt) -NoTypeInformation;
Compress-Archive -Path ($ZDrive + $fileName + $csvExt) -DestinationPath ($ZDrive + $fileName + $zipExt) -Force;
japespszx
  • 33
  • 5
  • 1
    As per the error, it is not able to pick the Z drive whatever you have created in PSDrive. Compress-Archive do not support paths containing PSDrives . Why not just compress in a local drive first, then create the PSdrive and just move it inside the drive. That makes the operation much more simpler – Ranadip Dutta Apr 20 '20 at 11:41
  • Makes sense. I'll go do that, thanks! I'll leave this question open, just in case there are future developments to PS or if anybody else has a solution. – japespszx Apr 20 '20 at 18:18
  • I will put the comment as an answer so that you can at least mark it as a solution. – Ranadip Dutta Apr 21 '20 at 07:33

0 Answers0