SharePoint Automation Series--create a local user and add to SharePoint

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.