I am working on a script to terminate three processes for all users except IT and System accounts. I managed to get the script working just fine on my machine, but when I run it on the server I receive an error (see below).
I found that the issue is my conditional operator "-notin". This operator is not available in version 2.0 of PS, and unfortunately the server has no upgrade path to a new version of PS.
I would greatly appreciate any input on how I can work around this issue.
$SafeSysUsers = @("NT AUTHORITY\NETWORK SERVICE","NT AUTHORITY\LOCAL SERVICE","NT AUTHORITY\SYSTEM")
$SafeUsers = @("User1","User2","User3")
$SafeAll = [array]$SafeSysUsers + $SafeUsers
Get-WmiObject win32_process -Filter "name='cmd.exe' OR name='calc.exe' OR name='notepad.exe'" | %{IF($_.GetOwner().User -notin $SafeAll){$_.Terminate()}}
ERROR:
Your must provide a value expression on the right-hand side of the '-' operator. At line:1 char:121
Unexpected token 'notin' in expression or statement. At line:1 char:122
Unexpected token 'SafeAll' in expression or statement. At line:1 char:128