0 votes

I am using this script to remove all users from groups when they are terminated. This script doesn't remove users from Azure only groups just on prem. How would I change this script to remove the Azure groups that we don't synchronize to on prem? $U = "%username%"

$Groups = Get-AdmPrincipalGroupMembership -Identity $U -AdaxesService localhost foreach($Group in $Groups){ $GN = $Group.samAccountName Try{ If($GN -ne 'NoAllExchange' -and $GN -ne 'Domain Users'){ Remove-AdmGroupMember -Identity $GN -Members $U -Confirm:$False -AdaxesService localhost } } Catch{ $Context.LogMessage("Can not remove $U from $GN"+$_.Exception.Message, "Information") }

}

by (1.0k points)

1 Answer

–1 vote
by (287k points)

Hello,

You can use one of the scripts from the following article in our repository: https://www.adaxes.com/script-repository/remove-all-group-memberships-for-a-user-account-s33.htm.

0

Hello, the script in the repository doesn't log the group removals in the Adaxes logs. I need that for audit puposes.

+1

Hello,

For each removal from group to be logged in Adaxes, replace this line in either of the scripts

$group = $Context.BindToObject($groupPath)

with the below one

$group = $Context.BindToObjectEx($groupPath, $True)
0

Thanks, this works perfectly.

Related questions

0 votes
1 answer

I would like to have a script that removes the offboarded users from all teams groups

asked Jan 3 by bodson (20 points)
0 votes
1 answer

https://www.adaxes.com/script-repository/remove-all-group-memberships-for-a-user-account-s33.htm I found this script but it only removes 365 groups, security groups, and ... user from all shared mailboxes they are a member of when disabling a user. Thanks!

asked Sep 8, 2023 by silicondt (60 points)
0 votes
1 answer

Hello! how do i manage do get adaxes to remove all groups from the user after one month? We have a Business Rule where you can add an end of Date when the Account ... value field the powershell script works but not with the +1 Month. Thanks for your help!

asked Jun 14, 2023 by eww ag (140 points)
0 votes
1 answer

Hi, would it be possible to script a workstation in AD and also directly from our local SCCM environment ?

asked 2 days ago by ddesmedt (40 points)
0 votes
1 answer

I've looked at https://www.adaxes.com/script-repository/copy-group-membership-from-specified-user-s590.htm. is there away to change from group names to a group type? Like exclude all distribution groups?

asked Dec 4, 2023 by Derek.Axe (480 points)
3,526 questions
3,217 answers
8,197 comments
547,625 users