PS Script to remove users from a group in same domain and other domains with in forest

Copper Contributor

I am trying to remove users from a group using PS but it will only allow me to remove users in that domain and not from other domain within the forest, (user not found error for other domain within forest) This is universal group and have members from other domain. can someone help me update script to remove users from all domains with in forest. This is a Bulk operation. 

 

something i found, but need fine tuning 

 

$DC_In_Root = (Get-ADDomain us.contoso.com).PDCEmulator
$DC_In_Default = (Get-ADDomain eu.contoso.com).PDCEmulator
$Group = "Test1234"
$Users = Import-Csv ".\Users.csv"
ForEach ($user in $Users){
$Default_Domain_User = Get-Aduser $user -server $DC_In_Default
Remove-ADGroupMember -Identity $Group -Members $Default_Domain_User -server $DC_In_Root
}

 

2 Replies

@Ajkbond 

 

Can you provide some sample rows from your CSV file?

 

Cheers,

Lain

This is interesting :thinking_face:, you should be part of the universal administration group, to list all the domain users, and search in the trusted domains, but also, you must specify the domain controller where you want to look at... have you search for it in the powershell gallery?