Advertisement
private775

Install/uninstall list custom action (button)

Mar 26th, 2015
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $scriptDir = Split-Path $script:MyInvocation.MyCommand.Path
  2. $configPath = "$($scriptDir)\configuration.ps1"
  3. . $configPath
  4.  
  5. $xmlPath = "$($scriptDir)\MoveToArchive.xml"
  6.  
  7. $lists = @{
  8.     "MWI" = @{
  9.         "ACTIONID" = "{3285FA3D-623C-4805-96D7-A935387D0772}"
  10.         "COMMANDGUID" = "{128A01C7-9833-4DCE-9507-FAD14A0B0959}"
  11.     }
  12. }
  13.  
  14. $jsFiles = @( "jquery-1.11.2.min.js", "handlebars-v3.0.0.js", "moment.min.js" )
  15.  
  16. function InstallCustomActions() {
  17.     $s = get-spsite $siteUrl
  18.     $w = $s.RootWeb
  19.     $xmlContent = [System.IO.File]::ReadAllText($xmlPath)
  20.  
  21.     $len = $jsFiles.Length
  22.     for($i = 0; $i -lt $len; $i++){
  23.         $scriptlink = $w.UserCustomActions.Add()
  24.         $scriptlink.Location = "ScriptLink"
  25.         $scriptlink.Name = $jsFiles[$i]
  26.         $scriptlink.ScriptSrc = "/_layouts/nova.bhb.policies.archive/JS/" + $jsFiles[$i]
  27.         $scriptlink.Update()
  28.     }
  29.  
  30.  
  31.     foreach($listName in $lists.Keys){
  32.         $xmlStr = $xmlContent
  33.         foreach($idName in $lists[$listName].Keys){
  34.             $xmlStr = $xmlStr.Replace($idName, $lists[$listName][$idName])
  35.         }
  36.         $l = $w.Lists.TryGetList($listName)
  37.         if($l -eq $null){
  38.             $errMsg = "List $($listName) doesn't exist"
  39.             throw $errMsg
  40.         }
  41.         $actionUnlockPayment = $l.UserCustomActions.Add()
  42.         $actionUnlockPayment.Location = "CommandUI.Ribbon"
  43.         #$actionUnlockPayment.Rights = [Microsoft.SharePoint.SPBasePermissions]::EditListItems -bor [Microsoft.SharePoint.SPBasePermissions]::DeleteListItems
  44.         $actionUnlockPayment.Sequence = 100
  45.         $actionUnlockPayment.Title = "Move to the Archive"
  46.         $actionUnlockPayment.CommandUIExtension = $xmlStr
  47.         $actionUnlockPayment.Update()
  48.     }
  49. }
  50.  
  51. function UninstallCustomActions() {
  52.     $s = get-spsite $siteUrl
  53.     $w = $s.RootWeb
  54.  
  55.     $len = $jsFiles.Length
  56.     for($i = 0; $i -lt $len; $i++){
  57.         $w.UserCustomActions|?{$_.Name -eq $jsFiles[$i] }|% { $_ } |% {$_.Delete()}
  58.     }
  59.  
  60.     foreach($listName in $lists.Keys){
  61.         $l = $w.Lists.TryGetList($listName)
  62.         if($l -eq $null){
  63.             $errMsg = "List $($listName) doesn't exist"
  64.             throw $errMsg
  65.         }
  66.         $l.UserCustomActions.Clear()
  67.         $l.Update()
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement