-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEnable-SPCustomScriptAction.ps1
50 lines (40 loc) · 1.79 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
<#
.SYNOPSIS
Enables the Custom Script embedded - as demo for allowing custom JS on new SPO Document Library UI
.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 Script Action |"
Write-Host -ForegroundColor White "--------------------------------------------------------"
Write-Host -ForegroundColor Yellow "Target Site URL: $targetSiteUrl"
try
{
Connect-SPOnline $targetSiteUrl -Credentials $Credentials
Apply-SPOProvisioningTemplate -Path .\Custom.Script.Action.Infrastructure.xml -Handlers Files
Apply-SPOProvisioningTemplate -Path .\Custom.Script.Action.Template.xml -Handlers CustomActions -Parameters @{"InfrastructureSiteUrl"=$targetSiteUrl}
Write-Host -ForegroundColor Green "Custom Script Action application succeeded"
}
catch
{
Write-Host -ForegroundColor Red "Exception occurred!"
Write-Host -ForegroundColor Red "Exception Type: $($_.Exception.GetType().FullName)"
Write-Host -ForegroundColor Red "Exception Message: $($_.Exception.Message)"
}