-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeploySP.ps1
82 lines (63 loc) · 5.21 KB
/
DeploySP.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
<#
.SYNOPSIS
Deploys the Information Architecture specified.
.DESCRIPTION
The DeploySP.ps1 script accepts an array of Function names which correspond with the type
of SharePoint artefacts to be deployed. Each function expects a corresponding CSV file with the same name
in the same folder (using $PSScriptRoot).
This script relies on the OfficeDev PnP-PowerShell cmdlets (https://github.com/OfficeDev/PnP-PowerShell)
which must be installed before use:
Install-Module SharePointPnPPowerShellOnline
OR
Install-Module SharePointPnPPowerShell2016
OR
Install-Module SharePointPnPPowerShell2013
.PARAMETER TargetSiteUrl
The URL of the target SharePoint Online site collection.
.PARAMETER CredentialLabel
The name of the generic credential (stored in Windows Credential Manager) to use to connect to the site.
.PARAMETER CSVFolderPath
The absolute path to a local folder containing the CSVs to process (must have matching named functions in FunctionsToRun).
.PARAMETER FunctionsToRun
A comma-separated array of functions to execute (must have matching CSVs in CSVFolderPath).
.EXAMPLE
.\DeploySP.ps1 -TargetSiteUrl https://contoso.sharepoint.com/sites/target -CredentialLabel contoso -CSVFolderPath "C:\Projects\Project1\CSVs" -FunctionsToRun ContentTypes,SiteColumns
.NOTES
#>
Param(
[string]$TargetSiteUrl,
[string]$CredentialLabel,
[string]$CSVFolderPath,
[string[]]$FunctionsToRun
)
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
$global:creds = $CredentialLabel
Set-Location $scriptPath
Try {
if($CredentialLabel -eq "web") {
Connect-PnPOnline -Url $TargetSiteUrl -UseWebLogin
} else {
Connect-PnPOnline -Url $TargetSiteUrl -Credentials $CredentialLabel
}
Write-Host "## Successfully connected to $TargetSiteUrl ##" -ForegroundColor Green
} Catch {
Write-Host "!! Failed to connect to $TargetSiteUrl - please check credentials !!" -ForegroundColor Red
Exit
}
if($FunctionsToRun.Contains("UnifiedGroups") -or $FunctionsToRun.Contains("RemoveUnifiedGroups")) {
Try {
Connect-PnPMicrosoftGraph -Scopes Group.ReadWrite.All
Write-Host "## Successfully connected to Microsoft Graph ##" -ForegroundColor Green
} Catch {
Write-Host "!! Failed to connect to Microsoft Graph !!" -ForegroundColor Red
Exit
}
}
#Load up the SharePoint Core Functions
. .\SP_Core.ps1
forEach ($function in $FunctionsToRun) {
. .\Functions\$function.ps1
[array]$Csv = @(Import-Csv $CSVFolderPath\$function.csv)
&(Get-Item "function:$function").ScriptBlock -Rows $Csv
}
Write-Host "## DONE ##" -ForegroundColor Green