michevnew/PowerShell

Exceptions

Closed this issue · 2 comments

This is going to be weird question, but is there a way for me to simply exclude 2 groups?

I have 2 groups that are teams groups and as soon as people get removed, it dings everyone in my company.

I have the object ID of the 2 groups, is there a simple line of code i could add to exclude them?

Really appreciate your help. I've been trying for hours. lol

Which script are we talking about here, the Remove_User_All_Groups.ps1 one? You can add an exception within the foreach loop (line 130), something like:

foreach ($Group in $Groups) {
if ($Group.DisplayName -eq "Team1") { continue }
...
}

It's better to use a unique-valued identifier, such as the ExternalDirectoryObjectId, but DisplayName should also do. Here's example with the former:

foreach ($Group in $Groups) {
if ($Group.ExternalDirectoryObjectId -eq "GUID") { continue }
...
}

I can't believe how fast you got back to me. Literally spent the last 2 hours pulling people in who know a little about the code. LOL. That fixed it!!!!! Thank you so much!!!! This is going to make my life a lot easier!