-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCreate-SPWebApplication.ps1
More file actions
80 lines (64 loc) · 6.94 KB
/
Copy pathCreate-SPWebApplication.ps1
File metadata and controls
80 lines (64 loc) · 6.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Function Create-DNSRecord([string] $DNSServer, [string] $DNSZone, [string] $DNSRecord, [string] $DNSRecordType, [string] $IPAddress) {
If ((Check-DNSRecordExists $DNSServer $DNSZone $DNSRecord $DNSRecordType) -eq $false) {
Invoke-Expression "dnscmd $DNSServer /RecordAdd $DNSZone $DNSRecord $DNSRecordType $IPAddress";
Write-Host "Created record for $DNSRecord";
} Else {
Write-Host "DNS entry already exists for $DNSRecord";
}
}
Function Check-DNSRecordExists([string] $DNSServer, [string] $DNSZone, [string] $DNSRecord, [string] $DNSRecordType) {
$dnscmdResponse = Invoke-Expression "dnscmd $DNSServer /EnumRecords $DNSZone $DNSRecord /Type $DNSRecordType";
If ($dnscmdResponse[1].ToString().Contains("failed") -eq $true) { Return $false; }
Else { Return $true; }
}
Function Create-SPWebApplication([string] $DNSRecord, [string] $DNSZone, [int] $port, [string] $appPool, [string] $appPoolCredentials,
[string] $databaseServer, [string] $databaseName, [string] $authenticationMethod) {
$Name = "SharePoint - $DNSRecord";
$HostHeader = "$DNSRecord.$DNSZone";
$URL = "https://$hostHeader";
$ap = New-SPAuthenticationProvider;
If(Check-AppPoolExists $AppPool) {
New-SPWebApplication -Name $name -HostHeader $hostHeader -Port $port -URL $url -ApplicationPool $appPool `
-DatabaseName $databaseName -DatabaseServer $databaseServer -AuthenticationMethod $authenticationMethod `
-AuthenticationProvider $ap -SecureSocketsLayer
} Else {
New-SPWebApplication -Name $name -HostHeader $hostHeader -Port $port -URL $url `
-ApplicationPool $appPool -ApplicationPoolAccount (Get-SPManagedAccount $AppPoolCredentials) `
-DatabaseName $databaseName -DatabaseServer $databaseServer -AuthenticationMethod $authenticationMethod `
-AuthenticationProvider $ap -SecureSocketsLayer
}
Write-Host "Created $Name";
}
Function Check-AppPoolExists([string] $AppPool) {
$Result = Get-SPWebApplication | Where { $_.ApplicationPool.Name -eq $AppPool }
If($Result) {
Return $true;
} Else {
Return $false;
}
}
Add-PsSnapin Microsoft.SharePoint.PowerShell -ea SilentlyContinue
$DNSRecord = "mvasample";
$Template = "DEV#0";
$Owner = "GEEKTRAINER\charrison";
$DNSServer = "geektrainerdc.geektrainer.com";
$DNSZone = "sharepoint2013.com";
$IPAddress = "192.168.42.21";
$DNSRecordType = "A";
$Name = "SharePoint - $DNSRecord";
$AppPool = "SharePoint 2013 - Web Sites";
$AppPoolCredentials = "GEEKTRAINER\sp2013service";
$DatabaseServer = "sql2012primary.geektrainer.com\sharepoint";
$DatabaseName = "SharePoint_{0}_Content" -f $DNSRecord;
$AuthenticationMethod = "NTLM";
$HostHeader = "{0}.{1}" -f $DNSRecord, $DNSZone;
$URL = "https://$hostheader";
$Port = 443;
$SiteName = $DNSRecord;
$Description = $DNSRecord;
Create-DNSRecord $DNSServer $DNSZone $DNSRecord $DNSRecordType $IPAddress;
Create-SPWebApplication $DNSRecord $DNSZone $Port $AppPool $AppPoolCredentials $DatabaseServer $DatabaseName $AuthenticationMethod
$site = New-SPSite $URL -OwnerAlias $Owner -Language 1033 -Template $Template -Name $SiteName -Description $Description;
#Create the default groups
$site.RootWeb.CreateDefaultAssociatedGroups($Owner, "", $SiteName);
$site.RootWeb.Update();