Create a SharePoint Site Collection through PowerShell.

Source: Internet
Author: User

Create a SharePoint Site Collection from PowerShell with the following code:

add-PSSnapin microsoft.sharepoint.powershellfunction createteamsite () {$webApps= get-spwebapplication $webAppsUrl=$webApps. Urlif($webApps. Count-eq1) {Write-host"You have the only one Web application:"Write-Host $webApps. Url $choice= Read-host"does want to create a site collection under this Web application? Type ' y ' to create. '"        if($choice-eq"y") {$siteTitle= Read-host"Enter The site collection ' s title:"$SITEURL= $webAppsUrl +"sites/"+$siteTitle Write-host"Choose The site collecion ' s Template:"Write-host"[1]. Fill in your template name."Write-host"[2]. Fill in your template name."Write-host"[3]. Fill in your template name."$choice= Read-host"Enter the number to choose:"switchsitetemplateandcreatesite $choice $siteUrl}} Else{Write-host"Choose The Web application:"         for($i =0; $i-le $webApps. Count; $i + +) {Write-host"["+ $i +"]."+$webApps [$i]. URL} $choice= Read-host"Enter the number to choose:"$siteTitle= Read-host"Enter The site collection ' s title:"$SITEURL= $webApps [$choice]. URL +"sites/"+$siteTitle Write-host"Choose The site collecion ' s Template:"Write-host"[1]. Fill in your template name."Write-host"[2]. Fill in your template name."Write-host"[3]. Fill in your template name."$choice= Read-host"Enter the number to choose:"switchsitetemplateandcreatesite $choice $siteUrl}} function Switchsitetemplateandcreatesite ($choice, $siteUrl) {Switch($choice) {1{$template ="fill in your template ID"}        2{$template ="fill in your template ID"}        3{$template ="fill in your template ID"}    }    if(($template-ne"fill in your template ID")-and ($template-ne"fill in your template ID")-and ($template-ne"fill in your template ID") {$choice= Read-host"Please enter the correct number."switchsitetemplateandcreatesite $choice $siteUrl}Else{Write-host"Site Collection Creating ..."New-spsite-url $SITEURL-owneralias"fill in your username"-language1033-Template $template Write-host"Site Collection created successfully."}}createteamsite

Parts of Chinese can be replaced (non-Chinese parts of the content can also be replaced to see individual needs.) ), you can extend the template ID in the switch statement (and add it accordingly at the prompt to fill in the template name). In daily work, choose a few common template ID and template name to fill in, username fill in your commonly used that can, preferably all the environment is universal user (so that the domain will not find users), do not fill the domain, because SharePoint support Fuzzy search, will automatically match the name you entered, such as when you enter Tylan, and if the user exists in SharePoint, SharePoint will automatically precede it with Domain in the check username, like this: "Domain\tylan".

In fact, written script is to facilitate the daily work, save time, specifically where to set the variables where the hard coding can be based on the needs of the work, and still to improve efficiency for the purpose. If it is a long-term project, in order to promote the use of a form tool is also possible, the key is to see if this is necessary.

Create a SharePoint Site Collection through PowerShell.

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.