Implementation process: Create a local user locally and add the user to the Administrators group, and then add the user to the SharePoint specified site and give Full Control permission.
The script is as follows:
functionaddusertospsite{param($SITEURL,$userName,$pwd,$fullName,$DSPT) #Create a local user and add to a local group.try{$computer= [ADSI]"winnt://$ENV: Computername,computer" $user=$Computer. Create ("User",$userName) $user. SetPassword ($pwd) $user. SetInfo ()$user. FullName =$fullName $user. Description =$DSPT #Ads_uf_passwd_cant_change + ads_uf_dont_expire_passwd $user. UserFlags = 64 + 65536$user. SetInfo ()$group= [ADSI]"Winnt://./administrators,group" $group. ADD ("winnt://$userName, user")}catch {Write-warning"User exists in local, no need to create new." } #ADD The new created local user to a SharePoint site. if((Get-pssnapin"Microsoft.SharePoint.PowerShell"-erroraction silentlycontinue)-eq $null) {Add-pssnapin"Microsoft.SharePoint.PowerShell" } $site= Get-spsite$SITEURL $web=$site. RootWeb$SPUserName=$env: COMPUTERNAME+"\"+$userNamestsadm-O Adduser-url$SITEURL-userlogin$SPUserName-role"Full Control"-username$SPUserName-useremail"[email protected]"}addusertospsite-siteurl"http://xxx-username"XXX"-pwd"XXX"-fullname"XXX"-dspt"XXX"
If you already have the user you want to add and you have successfully added user to the SharePoint site, you will be prompted:
SharePoint Automation Series--create a local user and add to SharePoint