Posted By GWHowarth88 on 26 Feb 2010 05:54 AM
It is possible to completely supress the window from appearing, however, you need to wrap the invocation of your script with a Visual Basic Script:
' Argument from command-line
strFile = WScript.Arguments(0)
Dim objShell, objFSO, objFile
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFile) Then ' Check to see if the file exists
Set objFile = objFSO.GetFile(strFile)
strCmd = "powershell -nologo -command " & Chr(34) & "&{" & objFile.ShortPath & "}" & Chr(34) ' Chr(34) is ""
objShell.Run strCmd, 0 ' 0 hides the window
Else
WScript.Echo "ERROR: " & strFile & " does not exist." ' Display error message if file does not exist
WScript.Quit
End If
Copy that into a text file, and save it as a .vbs file, then you can use it as such:
cscript "PathToMyVbsScript.vbs" "PathToMyPsScript.ps1"
Yes, I think that worked fine with PowerShell v1, but when I did some testing with v2 with the Task Scheduler (on XP SP3), a DOS command *still* appeared.