extract a zip file with a windows shortcut using PowerShell

I’m trying to extract a zip file using a Windows shortcut both the zip file and the shortcut are in the same folder I’ve tried to use Powershell to extract the zip file. I want to use PowerShell as the directory will be unknown.

I’ve used this PowerShell command in the target of the shortcut.

powershell.exe -ExecutionPolicy Bypass -NoExit -Command "$shortcutPath = Split-Path -Path $($MyInvocation.MyCommand.Definition) -Parent; Expand-Archive -Path `"$shortcutPath\file.zip`" -DestinationPath `"$Env:USERPROFILE\Desktop\Extracted`""

any help would be greatly appreciated thank you.

I was hoping for the zip file to be unzipped and for it to be placed on the desktop and for the new file to be called Extracted.

>Solution :

If the zip file is in the same location as your shortcut then why try to get the $shortcut path? You can just use a relative path passing the zip name as your argument:

powershell.exe -ExecutionPolicy Bypass -NoExit -NoProfile -Command "Expand-Archive file.zip -DestinationPath $Env:USERPROFILE\Desktop\Extracted"

Just make sure that your shortcut’s Start in argument is left blank so the path is always relative:


Leave a Reply