-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.ps1
152 lines (118 loc) · 5.81 KB
/
deploy.ps1
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<#
.SYNOPSIS
Provisions a GDPR Activity Hub site
.EXAMPLE
PS C:\> .\Provision-GDPRActivityHub.ps1 -SiteName "GDPRActivityHub" -SiteDescription "My GDPR Activity Hub" -Credentials $credentials
.EXAMPLE
PS C:\> .\Provision-GDPRActivityHub.ps1 -SiteName "GDPRActivityHub" -SiteDescription "My GDPR Activity Hub" -ConfigureCDN -CDNSiteName "CDN" -Credentials $credentials
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true, HelpMessage="The URL of the already created Modern Site")]
[String]
$GroupSiteUrl,
[Parameter(ParameterSetName = "CDN", Mandatory = $false, HelpMessage="Declares whether to create and configure a CDN in the target Office 365 tenant")]
[Switch]
$ConfigureCDN=$false,
[Parameter(ParameterSetName = "CDN", Mandatory = $false, HelpMessage="The name of the Team Site that will be created to support the CDN, e.g. ""CDN""")]
[String]
$CDNSiteName="CDN",
[Parameter(ParameterSetName = "CDN", Mandatory = $false, HelpMessage="The name of the Docuemnt Library that will be created to support the CDN, e.g. ""CDNFiles""")]
[String]
$CDNLibraryName="CDNFiles",
[Parameter(Mandatory = $false, HelpMessage="Optional tenant administration credentials")]
[PSCredential]
$Credentials,
[string]$userName="",
[string]$password=""
)
try
{
if($Credentials -eq $null -and $userName -ne "" -and $password -ne "")
{
#$Credentials = Get-Credential -Message "Enter Tenant Admin Credentials"
$Credentials = New-Object –TypeName "System.Management.Automation.PSCredential" –ArgumentList $userName, (ConvertTo-SecureString –String $password –AsPlainText -Force)
}
Connect-PnPOnline $GroupSiteUrl -Credentials $Credentials
# **********************************************
# Configure the Office 365 CDN, if requested
# **********************************************
$spoAdminCenterUrl = $GroupSiteUrl.replace(".sharepoint", "-admin.sharepoint")
$spoAdminCenterUrl = $spoAdminCenterUrl.substring(0, $spoAdminCenterUrl.IndexOf("sharepoint.com/") + 15)
$spoRootSiteUrl = $GroupSiteUrl.substring(0, $GroupSiteUrl.IndexOf("sharepoint.com/") + 15)
$spoTenantName = $spoRootSiteUrl.Substring(8, $spoRootSiteUrl.LastIndexOf("/") - 8)
$cdnSiteURL = $spoRootSiteUrl + "sites/" + $CDNSiteName
if ($ConfigureCDN.IsPresent)
{
Write-Host "Configuring the Office 365 CDN Settings"
$CDNDescription = "Content Delivery Network"
# Create the CDN Site
Connect-PnPOnline $spoAdminCenterUrl -Credentials $Credentials
# Determine the current username
$web = Get-PnPWeb
$context = Get-PnPContext
$user = $web.CurrentUser
$context.Load($user)
Execute-PnPQuery
$currentUser = $user.Email
# Create a new Site Collection
Write-Host "Creating CDN Site Collection"
New-PnPTenantSite -Title $CDNDescription -Url $cdnSiteURL -Description $CDNDescription -Owner $currentUser -Lcid 1033 -Template STS#0 -TimeZone 0 -RemoveDeletedSite -Wait
# Create the CDN Files library in the CDN site
Connect-PnPOnline $cdnSiteURL -Credentials $Credentials
New-PnPList -Title $CDNLibraryName -Url $CDNLibraryName -Template DocumentLibrary
# Create a folder in the CDNFiles document library
Write-Host "Uploading SPFx assets to the CDN"
$cdnFilesLibrary = Get-PnPList -Identity $CDNLibraryName
$packageFolder = $cdnFilesLibrary.RootFolder.Folders.Add("bot")
$context = Get-PnPContext
$context.Load($packageFolder)
Execute-PnPQuery
# Configure the CDN at the tenant level
Connect-SPOService -Url $spoAdminCenterUrl -Credential $Credentials
Set-SPOTenantCdnEnabled -CdnType Public -Confirm:$false
Add-SPOTenantCdnOrigin -CdnType Public -OriginUrl sites/$CDNSiteName/$CDNLibraryName -Confirm:$false
}
Connect-PnPOnline $cdnSiteURL -Credentials $Credentials
# Build and package the solution
Write-Host "Building SPFx package and bundling"
Push-Location hackBot
$cdnSiteAssetsFullUrl = "https://publiccdn.sharepointonline.com/" + $spoTenantName + "/sites/" + $CDNSiteName + "/" + $CDNLibraryName + "/bot"
& gulp update-manifest --cdnpath "$cdnSiteAssetsFullUrl"
& gulp clean
& gulp bundle --ship
& gulp package-solution --ship
Pop-Location
# Create a folder in the CDNFiles document library
Write-Host "Uploading SPFx assets to the CDN"
$cdnFilesLibrary = Get-PnPList -Identity $CDNLibraryName
$packageFolder = $cdnFilesLibrary.RootFolder.Folders.Add("bot")
$context = Get-PnPContext
$context.Load($packageFolder)
Execute-PnPQuery
foreach ($file in (dir hackBot\temp\deploy -File))
{
$fileStream = New-Object IO.FileStream($file.FullName, [System.IO.FileMode]::Open)
$fileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$fileCreationInfo.Overwrite = $true
$fileCreationInfo.ContentStream = $fileStream
$fileCreationInfo.URL = $file
$upload = $packageFolder.Files.Add($fileCreationInfo)
$context.Load($upload)
Execute-PnPQuery
}
#Write-Host -ForegroundColor Green "All the automatic steps are now completed!"
#Write-Host "Please proceed with the manual steps documented on the Setup Guide!"
$sppkgPath = (Get-Item -Path "hackBot\sharepoint\solution\bot.sppkg" -Verbose).FullName
#Import-PnPAppPackage -Path $sppkgPath -Force
Write-Host "You can find the .SPPKG file at the following path:" $sppkgPath
}
catch
{
Write-Host -ForegroundColor Red "Exception occurred!"
Write-Host -ForegroundColor Red "Exception Type: $($_.Exception.GetType().FullName)"
Write-Host -ForegroundColor Red "Exception Message: $($_.Exception.Message)"
}
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")