PowerShell - Add and Remove users from Active Directory Groups


PowerShell script to add and remove users from active directory groups on-prem

#import the ActiveDirectory Module

Import-Module ActiveDirectory


$users = @(













foreach($u in $users){


    Remove-ADGroupMember -Identity 'Office365_F3' -Members (Get-ADUser -Filter "userPrincipalName -eq '$u'" | Select -expand Name) -confirm:$false


    Add-ADGroupMember -Identity 'Office365-E3' -Members (Get-ADUser -Filter "userPrincipalName -eq '$u'" | Select -expand Name)


Share on Google Plus

About Tom DeMeulenaere

Highly accomplished information technology professional with extensive knowledge in System Center Configuration Manager, Windows Server, SharePoint, and Office 365.
    Blogger Comment


Post a Comment

Note: Only a member of this blog may post a comment.