forked from eoverfield/SP-Custom-Script-Action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enable-SPCustomScriptAction.ps1
52 lines (45 loc) · 2.13 KB
/
Enable-SPCustomScriptAction.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
<#
.SYNOPSIS
Enables deployment of customizations to SPO via custom actions
.EXAMPLE
PS C:\> .\Enable-SPCustomScriptAction.ps1 -TargetSiteUrl "https://intranet.mydomain.com/sites/targetSite"
.EXAMPLE
PS C:\> $creds = Get-Credential
PS C:\> .\Enable-SPCustomScriptAction.ps1 -TargetSiteUrl "https://intranet.mydomain.com/sites/targetSite" -Credentials $creds
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true, HelpMessage="Enter the URL of the target site collection, e.g. 'https://intranet.mydomain.com/sites/targetSite'")]
[String]
$TargetSiteUrl,
[Parameter(Mandatory = $false, HelpMessage="Optional administration credentials")]
[PSCredential]
$Credentials
)
if($Credentials -eq $null) {
$Credentials = Get-Credential -Message "Enter Admin Credentials"
}
Write-Host -ForegroundColor White "--------------------------------------------------------"
Write-Host -ForegroundColor White "| Enabling Custom Actions |"
Write-Host -ForegroundColor White "--------------------------------------------------------"
Write-Host -ForegroundColor Yellow "Target Site URL: $targetSiteUrl"
$dateStamp = Get-Date -Format "yyyy-MM-dd-hhmm"
$logFileName = ".\" + $dateStamp + "_" + $MyInvocation.MyCommand.Name.Replace(".ps1", "") + ".log"
Set-PnPTraceLog -On -LogFile ./logs/$logFileName -Level Debug
Connect-PnPOnline -Url $targetSiteUrl -Credentials $Credentials
try {
Apply-PnPProvisioningTemplate -Path .\Custom.QuickLaunch.Template.xml
Write-Host -ForegroundColor Green "Provisioning custom actions (menu skin and logo) to site collection."
Write-Host -ForegroundColor Green "Pausing 30 seconds."
Start-Sleep -Seconds 30
$subwebs = Get-PnPSubWebs -Recurse
Foreach ($web in $subwebs) {
Apply-PnPProvisioningTemplate -Path .\Custom.QuickLaunch.Template.Subsites.xml
Write-Host -ForegroundColor Green "Custom Action application succeeded in subsites."
}
}
catch {
Write-Host -ForegroundColor Red "Exception occurred! " + "Exception Type: $($_.Exception.GetType().FullName)"
Write-Host -ForegroundColor Red "Exception Message: $($_.Exception.Message)"
}