SCCM | Intune | Windows 365 | Windows 11 Forums

Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members. Please post your questions in the correct category.

NEW Finding and removing Domain admins in the local admin group

CodyB

Member
Messages
23
Points
1
How would I write this in PS in looking for "Company\Domain Admins" from local Admin group?

Get-LocalGroupMember -Group "Administrators" (Gives me a list of groups that are in the Local Administrators group)

If exist ""Company\Domain Admins"
Then
Remove-LocalGroupMember -Group "Administrators" -Member "Company\Domain Admins"
 
How would I write this in PS in looking for "Company\Domain Admins" from local Admin group?

Get-LocalGroupMember -Group "Administrators" (Gives me a list of groups that are in the Local Administrators group)

If exist ""Company\Domain Admins"
Then
Remove-LocalGroupMember -Group "Administrators" -Member "Company\Domain Admins"
Here you are:
$searchTerm = "Company\Domain Admins"
$group = "Administrators"
$adminGroup = Get-LocalGroupMember -Group $group
if ($adminGroup -like "*$searchTerm*"){
Remove-LocalGroupMember -Group $group -Member $searchTerm

}
 
Back
Top