0

I am looking to use the same Expand-Archive Powershell cmd to unzip the files but instead of using a local location for eg C:\Program Files\Folder\Folder\Folder\Folder" I am trying to extract the zip file into the logged on users profile so that the zip file will unpack it's payload into the users %APPDATA%\Folder\Folder\Folder\Folder\Folder

I have amended the -DestinationPath but it fails to unzip the contents into the users profile.but seems to just create a file named %APPDATA%

can anybody help ?

$SourcePath = "nameoffile.zip" $Destination = "C:\Program Files\Folder\Folder\Folder\Folder" Expand-Archive -Path $SourcePath -DestinationPath $Destination –Force write-host "nameofzipfile unzipped successfully"

Craig
  • 1
  • 1
  • Hi Craig. Simply change the destination. – Doug Maurer Nov 22 '21 at 19:48
  • Thanks for your response Doug changing the destination does not appear to work it seems to create a folder in the location named %appdata%\Folder\Folder\Folder\Folder\Folder rather than actually extracting the zip file contents into that location. – Craig Nov 22 '21 at 19:51
  • `%APPDATA%` means just a `string` to PowerShell, see this answer https://stackoverflow.com/a/10132925/15339544 – Santiago Squarzon Nov 22 '21 at 21:01
  • %appdata% is a cmd environment variable, not powershell. Your question isn’t “how do I access environment variables in powershell” – Doug Maurer Nov 22 '21 at 21:17

1 Answers1

1

%appdata% is a environment variable used by batch (cmd). if you want to use the same reference in powershell you use $env:appdata

$Destination = "$env:appdata\Folder\Folder\Folder\Folder\Folder"

Philip Meholm
  • 391
  • 1
  • 4