I am trying to run a PowerShell script through a batch file. I want to do this because I want to have my echo to be able to turn on my computer. (there are probably easier ways to send a WOL request from a echo, but I want to do it through PowerShell for learning purposes)
For the WOL command I have this (I do have the correct values for the dashes, I just don't want to show them):
Send-WOL -mac ------- -ip --------
Then my .bat file contains this:
@ECHO OFF
SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%script.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%'";
pause
Now when I run the .bat file I would get this error:
Send-WOL : The term 'Send-WOL' 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. At C:\Users\hao\Desktop\WOL main\Script.ps1:1 char:1 + Send-WOL -mac █████████████████ -ip █████████████ + ~~~~~~~~ + CategoryInfo : ObjectNotFound: (send-WOL:String) [], CommandNotFoundExeption + FullyQualifiedErrorId : CommandNotFoundExeption Press any key to continue . . .
even though when I put the exact same command within the script, manually into PowerShell it works perfectly.