question

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT asked YoungYang-MSFT answered

Delete AD Group/Members

Hi All

I have AD groups in csv file, i want to delete all the members of that groups. Will the below syntax help me.


Below is my csv file(there is space between Group and 01)

GroupName
Group 01
Group 02
Group 03

 $groups=import-csv "C:\myadgroups.csv" 
 foreach($group in $groups) 
 {    
 Get-ADGroupMember -Identity $group.GroupName | %{Remove-ADGroupMember -Identity $group.GroupName -Members $_.userprincipalname -Confirm:$false} 
 } 

If i need to delete group members for a single AD group will the below syntax help me.

 Get-ADGroupMember -Identity "Group 01" | %{Remove-ADGroupMember -Identity "Group 01" -Members $_.userprincipalname -Confirm:$false} 

If i need to delete AD groups will the below syntax help me

 import-csv "C:\myadgroups.csv" | %{ Remove-ADGroup -Identity $_."GroupName" -Confirm:$false} 


https://social.technet.microsoft.com/Forums/windowsserver/en-US/4349528c-f27e-48fa-869e-50ac40c978fb/delete-ad-groupmembers?forum=winserverDS#7bb5c409-97cf-4caf-a1ae-3e2f9c1395de

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YoungYang-MSFT avatar image
0 Votes"
YoungYang-MSFT answered

Hi,

Thanks for your question.

Also, the parameter "-members" of the cmdlet "Remove-ADGroupmember" cmdlet can accept Distinguished Name, GUID, Sid or samaccoutnname. Not the userprincipalname you used.

https://docs.microsoft.com/en-us/powershell/module/activedirectory/remove-adgroupmember?view=winserver2012-ps

Best regards,

Young Yang

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.