44 lines
1.0 KiB
PowerShell
44 lines
1.0 KiB
PowerShell
param(
|
|
[string]$url
|
|
)
|
|
|
|
function Add-Custom-Action($site, $actionUrl, $sequence)
|
|
{
|
|
Write-Host "Add custom action $actionUrl on" $site.Url -foregroundcolor green
|
|
$actions = $site.UserCustomActions
|
|
$contains = $false
|
|
foreach ($a in $actions)
|
|
{
|
|
#Write-Host " " $a.ScriptSrc
|
|
if ($a.ScriptSrc.ToLower() -eq $actionUrl.ToLower())
|
|
{
|
|
$contains = $true
|
|
#$a.Delete()
|
|
break
|
|
}
|
|
}
|
|
|
|
if ($contains)
|
|
{
|
|
Write-Host " Custom action is already added" -foregroundcolor yellow
|
|
return
|
|
}
|
|
|
|
$action = $site.UserCustomActions.Add()
|
|
$action.Location = "ScriptLink"
|
|
$action.ScriptSrc = $actionUrl
|
|
$action.Sequence = $sequence
|
|
$action.Update();
|
|
}
|
|
|
|
if (-not $url)
|
|
{
|
|
Write-Host "Specify site url in url parameter" -foregroundcolor red
|
|
return
|
|
}
|
|
|
|
$webApp = Get-SPWebApplication $url
|
|
$webApp.Sites | ForEach-Object { Add-Custom-Action $_ "/_layouts/15/taloyhtio/scripts/CustomAction.js?v=20200511" 10001 }
|
|
|
|
|