Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $scriptDir = Split-Path $script:MyInvocation.MyCommand.Path
- $configPath = "$($scriptDir)\configuration.ps1"
- . $configPath
- $xmlPath = "$($scriptDir)\MoveToArchive.xml"
- $lists = @{
- "MWI" = @{
- "ACTIONID" = "{3285FA3D-623C-4805-96D7-A935387D0772}"
- "COMMANDGUID" = "{128A01C7-9833-4DCE-9507-FAD14A0B0959}"
- }
- }
- $jsFiles = @( "jquery-1.11.2.min.js", "handlebars-v3.0.0.js", "moment.min.js" )
- function InstallCustomActions() {
- $s = get-spsite $siteUrl
- $w = $s.RootWeb
- $xmlContent = [System.IO.File]::ReadAllText($xmlPath)
- $len = $jsFiles.Length
- for($i = 0; $i -lt $len; $i++){
- $scriptlink = $w.UserCustomActions.Add()
- $scriptlink.Location = "ScriptLink"
- $scriptlink.Name = $jsFiles[$i]
- $scriptlink.ScriptSrc = "/_layouts/nova.bhb.policies.archive/JS/" + $jsFiles[$i]
- $scriptlink.Update()
- }
- foreach($listName in $lists.Keys){
- $xmlStr = $xmlContent
- foreach($idName in $lists[$listName].Keys){
- $xmlStr = $xmlStr.Replace($idName, $lists[$listName][$idName])
- }
- $l = $w.Lists.TryGetList($listName)
- if($l -eq $null){
- $errMsg = "List $($listName) doesn't exist"
- throw $errMsg
- }
- $actionUnlockPayment = $l.UserCustomActions.Add()
- $actionUnlockPayment.Location = "CommandUI.Ribbon"
- #$actionUnlockPayment.Rights = [Microsoft.SharePoint.SPBasePermissions]::EditListItems -bor [Microsoft.SharePoint.SPBasePermissions]::DeleteListItems
- $actionUnlockPayment.Sequence = 100
- $actionUnlockPayment.Title = "Move to the Archive"
- $actionUnlockPayment.CommandUIExtension = $xmlStr
- $actionUnlockPayment.Update()
- }
- }
- function UninstallCustomActions() {
- $s = get-spsite $siteUrl
- $w = $s.RootWeb
- $len = $jsFiles.Length
- for($i = 0; $i -lt $len; $i++){
- $w.UserCustomActions|?{$_.Name -eq $jsFiles[$i] }|% { $_ } |% {$_.Delete()}
- }
- foreach($listName in $lists.Keys){
- $l = $w.Lists.TryGetList($listName)
- if($l -eq $null){
- $errMsg = "List $($listName) doesn't exist"
- throw $errMsg
- }
- $l.UserCustomActions.Clear()
- $l.Update()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement