-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDisable-SPCustomScriptAction.ps1
More file actions
50 lines (40 loc) · 1.64 KB
/
Disable-SPCustomScriptAction.ps1
File metadata and controls
50 lines (40 loc) · 1.64 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
<#
.SYNOPSIS
Disables the Custom Script embedded demo
.EXAMPLE
PS C:\> .\Disable-SPCustomScriptAction.ps1 -TargetSiteUrl "https://intranet.mydomain.com/sites/targetSite"
.EXAMPLE
PS C:\> $creds = Get-Credential
PS C:\> .\Disable-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 "| Disabling Custom Script Action |"
Write-Host -ForegroundColor White "--------------------------------------------------------"
Write-Host -ForegroundColor Yellow "Target Site URL: $TargetSiteUrl"
try
{
Connect-SPOnline $TargetSiteUrl -Credentials $Credentials
$customAction = Get-SPOCustomAction -Scope Site | where { $_.Name -eq "RegisterUserScript" }
Remove-SPOCustomAction -Identity $customAction.Id -Scope Site -Force
Write-Host -ForegroundColor Green "Custom Script Action removal succeded"
}
catch
{
Write-Host -ForegroundColor Red "Exception occurred!"
Write-Host -ForegroundColor Red "Exception Type: $($_.Exception.GetType().FullName)"
Write-Host -ForegroundColor Red "Exception Message: $($_.Exception.Message)"
}