How can I add characters such as ';' ,'+', '=' into a string variable in a batch file?
Basically I am writing a batch file to write the psmodulepath of Powershell.
set "VAR=$env:PSmodulepath=$env:PSmodulepath+;C:\Powershellscripts\modules"
PowerShell.exe %VAR%
pause
I know this above code wont do me any good but I just want to understand how to pass the string correctly. When I run the batch file, I get the error as below :
C:\Users\Kiran_Vasanth\Desktop\Powe>PowerShell.exe $env:PSmodulepath=$env:PSmodu
lepath+;C:\Powershellscripts\modules
At line:1 char:37
+ $env:PSmodulepath=$env:PSmodulepath+;C:\Powershellscripts\modules
+ ~
You must provide a value expression following the '+' operator.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : ExpectedValueExpression
Any help?
The error comes from the powershell.The +
and =
are set to the variable . test with echo "%VAR%"
. Just powershell starts to execute this as a command.
May be you want this?
set "VAR=$env:PSmodulepath=$env:PSmodulepath+;C:\Powershellscripts\modules"
PowerShell.exe """%VAR%"""
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments