Tuesday, 6 April 2021

How to Remove Active Directory multiple user from the Multiple Group using PowerShell

 How to Remove Active Directory multiple users from   the Multiple Group using PowerShell


Csv file format for Users










Csv file format for Groups








Try

{

 $users = import-csv C:\Temp\Users.csv

 $groups = import-csv C:\Temp\Groups.csv

Foreach ($user in $users){

    Foreach ($group in $groups) {

         Remove-adgroupmember -Identity $group.GroupName -members $user.SamAccountName -Confirm:$false

    }

}

}

 Catch

{

Write-Host "An error occurred:"

       Write-Host $_

}

 

1 comment:

  1. difficlute to understand if possible merage csv

    ReplyDelete