I have tried several methods and have failed to get the script to launch from windows task manager.
So far I can run the scripts directly and they work fine but if I put them in windows task manager they not only fail to run they give no error or message that they failed. In all cases the script runs fine from being directly run or called but not from windows task manager. In addition I am using allsigned as execution policy.
So Here is the methods I have tried. Note. most of these methods are posted on the web.
1. Create PS Script and call from .cmd file with the following syntax: powershell -nologo -noninteractive -command "& {d:\scripts\powershellscript.ps1}"
2. Put the above command directly into the gui window in windows task manager.
3. Create PS Script and call from .vbs with the following syntax:
Dim objShell,objFSO,objFile
Set objShell=CreateObject("WScript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")
'enter the path for your PowerShell Script
strPath="d:\scripts\powershellscript.ps1"
'verify file exists
If objFSO.FileExists(strPath) Then
'return short path name
set objFile=objFSO.GetFile(strPath)
strCMD="powershell -nologo -command " & Chr(34) & "&{" &_
objFile.ShortPath & "}" & Chr(34)
'Uncomment next line for debugging
'WScript.Echo strCMD
'use 0 to hide window
objShell.Run strCMD,0
Else
'Display error message
WScript.Echo "Failed to find " & strPath
WScript.Quit
End If