Friday, March 8, 2013

SharePoint test user creation

Scenario:
We often need local test users, need to be created in Active Directory and also get them added to SharePoint site.

Solution:
Though of sharing what I use :)

Code:

clear

$user = "test.user1"
$userWithDomain = "contoso\"+$user

Import-Module activedirectory
New-ADUser -Name $user -AccountPassword (ConvertTo-SecureString "somepass" -AsPlainText -force) -Enabled $True -PasswordNeverExpires $True -PassThru 


Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.Powershell

New-SPUser -UserAlias $userWithDomain -Web http://sp2010 -Group "Team Owners"

0 comments: