Public/Remove-ADSIGroupMember.ps1
function Remove-ADSIGroupMember { <# .SYNOPSIS This function will remove Domain user from a Domain Group .EXAMPLE Remove-ADSIGroupMember -GroupSamAccountName TestGroup -UserSamAccountName Fxcat This will remove the domain user fxcat from the group TestGroup .NOTES Francois-Xavier Cat LazyWinAdmin.com @lazywinadm #> [CmdletBinding()] PARAM ($GroupSamAccountName, $UserSamAccountName) $UserInfo = [ADSI]"$((Get-ADSIUser -SamAccountName $UserSamAccountName).AdsPath)" $GroupInfo = [ADSI]"$((Get-ADSIGroup -SamAccountName $GroupSamAccountName).AdsPath)" IF (Test-ADSIUserIsGroupMember -GroupSamAccountName $GroupSamAccountName -UserSamAccountName $UserSamAccountName) { Write-Verbose "Removing $UserSamAccountName from $GroupSamAccountName" $GroupInfo.Remove($UserInfo.ADsPath) } ELSE { Write-Verbose "$UserSamAccountName is not member of $GroupSamAccountName" } } |