Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Get-Process: User Filtering

$
0
0

I am trying to write a PS script that will stop running processes for select users, and I am having trouble applying the filter for the Users. I need the script to stop the process for all users logged onto the system except for Network Service, Local Service, System, and a few of the domain administrators.

 

Here is what I have so far.

$Proc = @("Notepad","Calc")

$SafeSysUsers = @("NT AUTHORITY\NETWORK SERVICE","NT AUTHORITY\LOCAL SERVICE","NT AUTHORITY\SYSTEM")

$SafeUsers = @("ABC\123")

$Processes = Get-Process -Name $Proc -IncludeUserName | Where {$_.username -ne $SafeSysUsers -or $SafeUsers}


When I call $Processes I see that the ABC\123 is not filtered out.

 

I'm not sure if I am taking the correct approach to this, but I would appreciate any help or guidance. Thank you!


Viewing all articles
Browse latest Browse all 6937

Trending Articles