Powershell script sterge o lista de utilizatori din mai multe grupuri in acelasi timp

Configurare noua (How To)

Situatie

$users = import-csv C:\Users\admin.costeami\DesktOp\NRT-TEST.CSV
$groups = Get-ADGroup -Filter {Name -like “*_SB_*”} |select -ExpandProperty name
Foreach ($group in $groups) {
Foreach ($user in $users) {
Try{
#Set-ADUser $user.samaccountname -Description “Was member of $group”
Remove-ADPrincipalGroupMembership $user.samaccountname -member $group -confirm:$false -ErrorAction Stop
Write-Host “removing $($user.samaccountname) from $group” -ForegroundColor green
Write-Output “User $($user.samaccountname) removed from $group ” |Out-File “C:\Users\admin.costeami\Desktop\NRT-TEST2.txt” -Append
}

Catch
{write-warning “$_ Error removing user $($User.samaccountname)”}
}
}

Solutie

Tip solutie

Permanent

Voteaza

(4 din 11 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?