Problem: passing a local path to powershell.exe that includes square brackets in the folder names means that powershell cannot find the script file passed to it.
Option 1: use powershell -File .\MyScript.ps1
Option 2: use powershell %CD%\MyScript.ps1
I am not clear why powershell cannot find your path, but the -File command line argument seems to fix it. As does using the %CD% batch file property instead of '.'
If I create a file "HelloWorld.ps1" containing the single line:
Write-Output "Hello World"
in a folder
c:\work\joel\scream
and run the command:
C:\work\joel\scream>powershell .\HelloWorld.ps1
then I get the expected output (Hello World).
If I rename the folder to [scream], it fails.
cd ..
ren scream [scream]
Square brackets is a range operator.
C:\work\joel\[scream]>powershell .\HelloWorld.ps1
now yields:
.\helloworld.ps1 : The term '.\helloworld.ps1' is not recognized as the name
of a cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included, verify that the path is correct and try
again.
However running:
C:\work\joel\[scream]>powershell -File .\HelloWorld.ps1
gives the expected output (Hello World).
powershell /?
<snip/>
-File
Runs the specified script in the local scope ("dot-sourced"), so that the
functions and variables that the script creates are available in the
current session. Enter the script file path and any parameters.
File must be the last parameter in the command, because all characters
typed after the File parameter name are interpreted
as the script file path followed by the script parameters.
I'm not clear whether powershell or the command prompt / batch script is misinterpreting the path but I can say that while:
C:\work\joel\[scream]>powershell .\HelloWorld.ps1
does not work:
C:\work\joel\[scream]>powershell %CD%\helloworld.ps1
does work. so it appears to be related to the expansion of '.' into the current path.