How to add Active Directory group to SharePoint 2013/2016 using Powershell?

Hi Fellow SharePointers,

If you want to give acccess to your Sharepoint Site document library or list using Powershell. Here is the source code to achieve the same.

 

$web = get-spweb “http://mysharepointsite”
$account = $web.EnsureUser($Groupfull)
$Assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$role = $web.RoleDefinitions[“Read, Contribute, or Design”]
$Assignment.RoleDefinitionBindings.Add($role)
$web.RoleAssignments.Add($assignment)
$web.dispose()

 Happy Sharepointing folks!!

Leave a Reply

Your email address will not be published.