PowerShell script to add users to SharePoint group by login
Not so long ago I had to add 2 hundred users to SharePoint group. First I wanted to add them partially, but I understood that to do it via PowerShell is faster.
Below I write down a PowerShell script to add users to SharePoint group by login. It will decrease the time to complete the same task next time.
#Script to add users to SharePoint group by login name Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue cls $web = get-spweb "https://spdev/mySite" $group = $web.SiteGroups["my Group Name"] $users = ('domain\user1', 'domain\user2', 'domain\user3', 'domain\user4', 'domain\user5') foreach($user in $users) { $myuser = $web.EnsureUser($user) Write-Host $myuser $group.AddUser($myuser) }