Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using a .cmd file to launch PowerShell scripts in a Temp folder

I’m trying to use a .cmd file to open a PowerShell script (p.ps1) in a Windows users temporary folder (specifically C:\Users\Username\AppData\Local\Temp).

However, using @echo off PowerShell.exe -ExecutionPolicy Bypass -File "$env:temp/p.ps1" errors out as "$env:temp/p.ps1" doesn’t work with the File parameter.

While hard-coding the path to the PowerShell script works in launching the scripts, the cmd file will not work with separate users or lettered drives aside from mine. Looking for any suggestions on how to get over this hurdle.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

@echo off PowerShell.exe -ExecutionPolicy Bypass -File "%TEMP%/p.ps1"

Here’s some a of other Windows Environment Variables for CMD.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading