Read SharePoint List to ADD and Remove members from AD Group

SharePoint, Microsoft’s powerful collaboration and document management platform, offers a wealth of capabilities for organizations to streamline their business processes.

Today we will use SharePoint list together with PowerShell script to automate the process of adding and removing user from AD group.

I will explain the process and provide you with sample script that you can utilize in your environment and automate many of processes following the example.

Step 1

Create a SharePoint list with below columns.


ADGroup
à AD Group Name

Action
à ADD or REMOVE (choose choice column for it)

Member
à UserPrincipalName of the User

Status
à Set it to InProgress for the script to work (Script will set it to complete after it adds or remove the user from the group. (Choice Field with Value InProgress, Completed and Error)

erroremail à To receive error if occurred during addition or removal.

Create an entry in the list:

STEP 2

Schedule or RUN the PowerShell Script that will read this request and process it.

Prerequisites for this Solution:

Download the script from Git.

SPOList2AD.ps1

https://github.com/VikasSukhija/Downloads

Update the Script with below variables as per your environment:


After updating the SharePoint Site list and other variables, run the script with the account that has rights to AD as well as this SharePoint site.

Script will auto generate encrypted password first time it is run and save it in the same folder.


Log will be generated and stored in logs folder.

Count of changes is set to 500 to stop processing if requests are more than 500, you can set it as per your needs.

BatchSize is 5000 to remove the limitation of list view threshold of SharePoint.

Log Recycling is set to 60 days, you can change it as per your needs.

After completion script will update the status to Complete or Error in case error has occurred.

You can build PowerAPP or any other process on the top of it and automate it end to end.

I hope this sample solution will open a lot of opportunities that you can create and automate.

 

 

Thanks for reading …

Tech Wizard

 

https://techwizard.cloud

https://syscloudpro.com/

PowerShell Fast Track

 

Leave a comment