There is another way you can get this error, associated with spaces in file paths which is still common in windows even to this very day.
Let's say you had access to the common knowledge that in powershell, you need to escape spaces in filenames with a backtick, `, also known as a grave operator.
You could then use it like this in a batch script to run a powershell script, both of which are in the same sub-directory of a directory path that has spaces in it:
@REM get directory of the batch file script to use for powershell script
set cwd=%~dp0
@REM escape the spaces for powershell
set cwd=%cwd: =` %
echo %cwd%
@REM list the powershell script with a powershell command
powershell.exe -c Get-ChildItem "%cwd%install.ps1"
@REM run the powershell script
powershell.exe -File "%cwd%install.ps1"
Get-ChildItem will work, but powershell will not find the script as an argument of -File.
In fact, as it turns out, escaping the spaces is NOT needed for the -File argument, even as it is needed for Get-ChildItem. So this will work:
set cwd=%~dp0
set cwd1=%cwd: =` %
echo %cwd%
echo %cwd1%
powershell.exe -c Get-ChildItem "%cwd1%install.ps1"
powershell.exe -File "%cwd%install.ps1"
And yes I found this out because I'm running powershell script in batch script for same reason as OP. 13 years later.