A script that is run by Task Scheduler has a parent process whose name is svchost
, so you can use the following code in your script to detect this:
'svchost' -eq (Get-Process -Id (Get-CimInstance Win32_Process -Filter "ProcessID = $pid").ParentProcessId).Name
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…