Created
May 16, 2014 16:36
-
-
Save AspenForester/aa0e25f17772775024dc to your computer and use it in GitHub Desktop.
A couple of quick functions for AD group maintenance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# requires version 3.0 | |
<# Clear-ADGroupMember | |
.Synopsis | |
Removes all users from an AD group | |
.DESCRIPTION | |
Removes all users from an AD group provided to the script. | |
.EXAMPLE | |
“my-group” | Clear-ADGroupMember | |
#> | |
function Clear-ADGroupMember { | |
[CmdletBinding()] | |
#[OutputType([Microsoft.ActiveDirectory.Management.ADGroup])] | |
Param( | |
# Identity of Group to depopulate | |
[Parameter(Mandatory=$true, | |
ValueFromPipelineByPropertyName=$true, | |
Position=0)] | |
$Identity | |
) | |
Begin | |
{ | |
} | |
Process | |
{ | |
$ExistingGroup = Get-ADGroupMember $Identity | |
Remove-ADGroupMember -Identity $Identity -Members $ExistingGroup | |
} | |
End | |
{ | |
} | |
} # End Function Clear-ADGroupMember |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-UnusedGroup { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory = $True)] | |
[string] | |
$searchBase | |
) | |
Get-ADGroup -Filter * -Properties members, isCriticalSystemObject -SearchBase $searchBase | | |
Where-Object { ($_.members.count -eq 0 -AND !($_.IsCriticalSystemObject) -AND $_.DistinguishedName -notMatch 'Exchange Security' -AND $_.DistinguishedName -notMatch 'Dns') } | |
$searchBase = $null | |
} #end function Get-UnusedGroup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment