Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expand-Archive in powershell is failing to extract nested folders and files

Tags:

People also ask

Does expand-archive create folder?

By default, Expand-Archive creates a folder in the current location that is the same name as the ZIP file. The parameter allows you to specify the path to a different folder. The target folder is created if it does not exist. Forces the command to run without asking for user confirmation.


I have the following simple powershell to extract a zip folder (containing other folders and only log files) to a destination

$FolderPath = "C:\Temp\Whatever"

Expand-Archive -Path "$FolderPath\logs.zip" -DestinationPath "$FolderPath\logs"

Unfortunately this returns a whole bunch of errors like below....

Remove-Item : Cannot find path 'C:\Temp\Whatever\logs\1_Selenium SEPA-Test\Attempt1\1_Start VM's\Release\1_Initialize Agent.log' because it does not exist.
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:410 char:46
+ ...                 $expandedItems | % { Remove-Item $_ -Force -Recurse }
+                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Temp\Whateve...alize Agent.log:String) [Remove-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand

Remove-Item : Cannot find path 'C:\Temp\Whatever\logs\1_Selenium SEPA-Test\Attempt1\1_Start VM's\Release\1_Initialize Job.log' because it does not exist.
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:410 char:46
+ ...                 $expandedItems | % { Remove-Item $_ -Force -Recurse }
+                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Temp\Whateve...tialize Job.log:String) [Remove-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand

and loads of other errors that are similar

I can confirm that the file referenced in the first error C:\Temp\Whatever\logs\1_Selenium SEPA-Test\Attempt1\1_Start VM's\Release\1_Initialize Agent.log does exist in the zip folder at an equivalent location...

enter image description here

After the script concludes, I do a see an incomplete folder in the directory specified.

enter image description here

Whats going on here?

Thanks,