For some reason I am unable to get this function to execute properly from a cmd line / batch file call.
function streamMonitor {
[cmdletbinding()]
param(
[string]$directoryPath,
[string]$scriptToRestartPath
)
... the rest of my code
}
After digging through tons of forums and asking chatgpt here is one of the many things have tried and I believe should totally work but isnt.
Powershell.exe -executionpolicy remotesigned -File C:\pathto\streamMonitor.ps1 -directoryPath "C:\pathto\stream1" -scriptToRestartPath "C:\pathto\stream1.bat"
When executed, the terminal doesnt throw a syntax error but the powershell script doesn't run either.
You're creating a function, but you aren't calling it. Here is a version that outputs the two parameters you entered. Thanks to mklement0 for pointing out that my original script wasn't an exact fit.
Here is a version that passes the parameters in calling the script as different from the parameters used for the function.
And here is a version that just uses one set of parameters.