Reputation: 23
I have a batch file Install.bat which calls the GetVersion.ps1 powershell script. These two scripts are in the same folder (C:\Install_Media) and i am calling the powershell script by getting the directory where the batch file is(using %~dp0%).
The following code works good if there is no space in the path where these files are located. If there is a space in the path then shellscript is not getting executed (eg C:\Install Media). The script stops saying that The term 'C:\Install' is not recognized as the name of a cmdlet, function, script..
@ECHO OFF
set SRC_DIR=%~dp0%
Powershell set-executionPolicy remotesigned
Powershell %SRC_DIR%\GetSLMClientVersion.ps1
Powershell set-executionPolicy restricted
Upvotes: 2
Views: 2728
Reputation: 200483
Parameter expansion uses just a single %
character at the beginning of the expression. Also, you don't need to change the execution policy back and forth. powershell.exe
has a parameter for temporarily overriding the execution policy. And spaces in the path are best handled by putting the path in quotes, as TheIncorrigible1 pointed out in the comments.
Change your code to this:
@echo off
powershell.exe -ExecutionPolicy Bypass -File "%~dp0\GetSLMClientVersion.ps1"
Upvotes: 6