Forked from janikvonrotz/New-SPSiteWithCustomWebAppAndPoolAndAccount.ps1
Created
July 14, 2016 22:03
-
-
Save petersgiles/2e71f8bfba4cdb702b7f701d5c7cc503 to your computer and use it in GitHub Desktop.
PowerShell: Create a new SharePoint Site with a custom web application and managed account and application pool
#PowerShell
#SharePoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# modules | |
Import-Module ActiveDirectory | |
if((Get-PSSnapin 'Microsoft.SharePoint.PowerShell' -ErrorAction SilentlyContinue) -eq $null){Add-PSSnapin 'Microsoft.SharePoint.PowerShell'} | |
# new service account | |
$UserName = "SharePoint Service User Wiki" | |
$UserUPN = "[email protected]" | |
$UserSam = "sa-spwiki" | |
$UserPassword = "pass." | |
if(-not (Get-ADUser -Filter {sAMAccountName -eq $UserSam})){ | |
New-ADUser -Name $UserName -UserPrincipalName $UserUPN -SamAccountName $UserSam | |
Get-ADUser $UserSam | %{ | |
Set-ADAccountPassword -Identity $UserSam -NewPassword (ConvertTo-SecureString -String $UserPassword -AsPlainText -Force) -Reset | |
Enable-ADAccount -Identity $_ | |
Set-ADAccountControl -Identity $_ -PasswordNeverExpires $true -CannotChangePassword $true | |
Set-ADUser -Identity $_ -ChangePasswordAtLogon $false | |
$_ | |
} | |
} | |
# new sp service account | |
$ManagedAccountName = $UserSam | |
$ManagedAccountPassword = $UserPassword | |
if(-not (Get-SPManagedAccount $ManagedAccountName)){New-SPManagedAccount -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ManagedAccountName,(ConvertTo-SecureString -String $ManagedAccountPassword -AsPlainText -Force))} | |
# New Applicaton Pool | |
$PoolName = "SP_wiki" | |
$PoolAccount = $UserSam | |
if(-not (Get-SPServiceApplicationPool $PoolName)){New-SPServiceApplicationPool -Name $PoolName -Account $UserSam} | |
# New SPWeb Application | |
$AppName = "SP_wiki" | |
$AppPort = 80 | |
$AppUrl = "http://wiki.vbl.ch" | |
$AppHostHeader = "wiki.vbl.ch" | |
$AppDatabaseServer = "VBL_SHAREPOINT" | |
$AppDatabaseName = "SP_Content_wiki" | |
$AppPoolName = $PoolName | |
$AppPoolAccount = $UserSam | |
if(-not (Get-SPWebApplication $AppName)){New-SPWebApplication -Name $AppName -ApplicationPool $AppPoolName -ApplicationPoolAccount (Get-SPManagedAccount $AppPoolAccount) -HostHeader $AppHostHeader -Port $AppPort -URL $AppUrl -DatabaseServer $AppDatabaseServer -DatabaseName $AppDatabaseName} | |
# New SPSite | |
$SiteName = "Informatik Wiki" | |
$SiteUrl = $AppUrl | |
$SiteTemplate = "ENTERWIKI#0" | |
$SiteOwnerMail = "[email protected]" | |
$SiteOwnerAlias = "vonrotz" | |
if(-not (Get-SPSite -Identity $Siteurl)){New-SPSite -Url $SiteUrl -Template $SiteTemplate -Name $SiteName -OwnerEmail $SiteOwnerMail -OwnerAlias $SiteOwnerAlias} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import-Module ActiveDirectory | |
if((Get-PSSnapin 'Microsoft.SharePoint.PowerShell' -ErrorAction SilentlyContinue) -eq $null){Add-PSSnapin 'Microsoft.SharePoint.PowerShell'} | |
# add managed path | |
$WebApplication = "http://sharepoint.domain.ch" | |
$RelativeURLExplicit = "/itwiki" | |
New-SPManagedPath -RelativeURL $RelativeURLExplicit -WebApplication $WebApplication -Explicit | |
# add content database | |
$SPContentDatabaseName = "SP_Content_ITWiki" | |
New-SPContentDatabase -Name $SPContentDatabaseName -WebApplication $WebApplication | |
$SiteName = "Informatik Wiki" | |
$SiteUrl = "http://sharepoint.domain.ch/itwiki" | |
$SiteTemplate = "ENTERWIKI#0" | |
$SiteOwnerAlias = "SP1_Pool_Intranet" | |
$SiteSecondaryOwnerAlias = "SP1_Admin" | |
New-SPSite -Url $SiteUrl -Template $SiteTemplate -Name $SiteName -OwnerAlias $SiteOwnerAlias -SecondaryOwnerAlias $SiteSecondaryOwnerAlias -ContentDatabase $SPContentDatabaseName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment