only sound and no alert/PowerShell windows if "Run whether user is logged on or not" is selected
You can never use that TS setting for anything that has a user interface.
The desired state is having the alert window displayed but not the PowerShell window. I’ve tried using the run “Hidden” option but that didn’t do the trick.
How do I get the alert window without the PowerShell window?
The solution I adopt for batch files is not to run them directly from TS but to use TS to trigger a vbs intermediary that starts the batch file [normally, minimised, hidden - as required]
So the TS task action would be
In your case, the argument would be "D:\Computer\Scripts\StartBU_StorSpaceStat.vbs"
The vbs file would be this in order to run the PS1 hidden
StartBU_StorSpaceStat.vbs
Code:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "Powershell.exe -File " & chr(34) & "D:\Computer\Scripts\BU_StorSpaceStat.ps1" & Chr(34), 0
Set WshShell = Nothing
If I wanted the PS1 to run minimised instead, I'd use
StartBU_StorSpaceStat.vbs
Code:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "Powershell.exe -File " & chr(34) & "D:\Computer\Scripts\BU_StorSpaceStat.ps1" & Chr(34), 7
Set WshShell = Nothing
I normally point my vbs intermediaries to a shortcut to the script instead of the script itself. That allows me to set a specific icon to appear in the Taskbar. I always set the shortcut to run Minimised even if I'm going to use the vbs intermediary to hide it completely - I just find that this eases testing the whole thing. Note that, for a ps1 file, you make a normal shortcut then add
powershell.exe -file
in the front of the Target field.
- It would otherwise just open the ps1 in Notepad instead of running it.
If I wanted the PS1 to run hidden yet refer to the shortcut, I'd use
StartBU_StorSpaceStat.vbs
Code:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "D:\Computer\Scripts\BU_StorSpaceStat.lnk" & Chr(34), 0
Set WshShell = Nothing
or, finally, to run the PS1 minimised whilst referring to the lnk to get the icon, I'd use
StartBU_StorSpaceStat.vbs
Code:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "D:\Computer\Scripts\BU_StorSpaceStat.lnk" & Chr(34), 7
Set WshShell = Nothing
These are my batch file notes on the subject. I have yet to add the ps1 variations [above] to it.
Make Task scheduler run a batch file minimised and with a specific icon - TenForums
but that icon applies only to the batch file or PS1 window itself not to any dialog that it generates. Dialogs have their own Taskbar icons generated by their own code.
That article also contains a guide to protecting the folders used to house scripts. In my case, C:\Tools & its subfolders and in yours D:\Computer\Scripts
Denis