I'm simply trying to run a .ps1 from a .vbs (did this before on w10)
C:\Scripts\Test.vbs
command = "powershell.exe -ExecutionPolicy Bypass -nologo -command C:\Scripts\Test.ps1"
set shell = CreateObject("WScript.Shell")
shell.Run command
Error: (when opening .vbs) (uses windows based script host)
C:\Scripts\Test.ps1 : The term 'C:\Scripts\Test.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
Every .ps1 script run by powershell spawned by running a .vbs this way results in this error.
The .ps1 file works fine when opened manually in powershell
The actual error is more revealing:
This is not a Windows 11 issue. I tested your script and found that it failed to execute the ps1 file on my Windows 10 machine. After retyping the script, it worked fine. The difference: ANSI vs UTF-8 encoding.
When you change the encoding to ANSI (e.g. using NotePad), the path will become
??C:\Scripts\Test.ps1. Just delete the question marks and save. It should now work correctly.Note: The string
C:\Scripts\Test.ps1is exactly the same encoding for ANSI and UTF-8. The problem (based on the text posted in the question) is that this string was preceded byE2 80 AA (U+202A, Left-To-Right Embedding). Removing that invisible character fixes the path.Note: As stated in the comments, you should use
-fileinstead of-commandbut it will work either way once the encoding is corrected.