I have a Powershell script that queries a specified OU for computer names and then runs a batch script on each computer (the script kicks off a reboot but prompts the user to cancel if they’d like). I would like to know how I can specify an exclusion group in this script. Say I have a group in Active Directory called WeekendRebootExclusion with some computers as members. How would I exclude these machines from the process in the script?
There’s no easy way to do that, because AD doesn’t track information quite that way.
Inside your ForEach loop, before your Start-Process command, you’ll need to check and see if the computer is a MemberOf that group. If it is, then don’t run your Start-Process (an If{} construct).