Advertisement
private775

Make SharePoint designer workflow re-usable

Dec 22nd, 2014
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # download SharePoint designer workflow from Site Assets
  2. # and update solution and feature IDs to match previous version
  3. $version = "2.0"
  4.  
  5. if($args -ne $null -and $args.Length -gt 0){
  6.   $version = $args[0]
  7. }
  8.  
  9. $origWspFile = "Workflow Process 2.0.wsp"
  10. $destWspFile = $origWspFile.Replace("2.0.wsp", "$($version)_new.wsp")
  11. $webFolder = "http://devintranet/sites/workflowssite/SiteAssets"
  12. $workDir = "C:\DeploymentScripts\workflowssite\$($version)"
  13. $destDir = "$($workDir)\WSP"
  14.  
  15. $webFile = "$($webFolder)/$($origWspFile)"
  16. $wspFile = "$($workDir)\$($origWspFile)"
  17. $userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2;)"
  18.  
  19. Remove-Item -Recurse -Force $workDir -ErrorAction SilentlyContinue
  20. New-Item  $workDir -type directory
  21.  
  22. set-location $workDir
  23. $wc = New-Object System.Net.WebClient
  24. $wc.UseDefaultCredentials = $true
  25. $wc.Headers.Add("user-agent", $userAgent)
  26. $wc.DownloadFile($webFile, $wspFile)
  27.  
  28. Remove-Item -Recurse -Force $destDir -ErrorAction SilentlyContinue
  29. New-Item  $destDir -type directory
  30. expand -R -F:* "$($origWspFile)" WSP
  31.  
  32. $fps = "$($destDir)\manifest.xml"
  33. $xml = [xml](Get-Content $fps)
  34. $xml.Solution.SolutionId = "{dd48ffd2-6ee3-4cba-94c0-721887f2ad1c}"
  35. $xml.Save($fps)
  36.  
  37. $fpf1 = "$($destDir)\Workflow Process 2.0WebEventReceivers\Feature.xml"
  38. $xml = [xml](Get-Content $fpf1)
  39. $xml.Feature.Id = "{4be55305-1708-4a75-a537-2682e7c77550}"
  40. # $xml.Feature.Version = "$($version).0.0"
  41. $xml.Save($fpf1)
  42.  
  43.  
  44. $fpf2 = "$($destDir)\Workflow Process 2.0ListInstances\Feature.xml"
  45. $xml = [xml](Get-Content $fpf2)
  46. $xml.Feature.Id = "{ea607063-4ad3-4414-b837-605794944cb2}"
  47. $xml.Feature.Title = "Workflow Process Workflow"
  48. # $xml.Feature.Version = "$($version).0.0"
  49. $xml.Save($fpf2)
  50.  
  51.  
  52. $len = $destDir.Length + 1
  53. $files = Get-ChildItem $destDir -Recurse |?{ -not $_.PSIsContainer }|%{$_.FullName}|%{$_.SubString($len)}
  54.  
  55. $ddfTemplate = @"
  56. ;*** Diamond Directive File
  57. ;
  58. ;
  59. .OPTION EXPLICIT                    ; Generate errors on variable typos
  60. ;
  61. .Set CabinetNameTemplate=ppp.cab    ; The name of the WSP file
  62. .set DiskDirectoryTemplate=CDROM    ; All cabinets go in a single directory
  63. .Set CompressionType=MSZIP          ;
  64. .Set Cabinet=on                     ;
  65. .Set Compress=on                    ;
  66. .Set DiskDirectory1=.               ; Use the specified directory for the output CAB file
  67. ;
  68. ;*** Disable size limits for wsp (cab) files ;
  69. ;
  70. .Set CabinetFileCountThreshold=0
  71. .Set FolderFileCountThreshold=0
  72. .Set FolderSizeThreshold=0
  73. .Set MaxCabinetSize=0
  74. .Set MaxDiskFileCount=0
  75. .Set MaxDiskSize=0
  76. ;
  77. ;*** Files to zip                   ;
  78. ;
  79. "@
  80.  
  81. $lines = $ddfTemplate.Split([string[]]"`n",'None')
  82.  
  83.  
  84. $ddfFilePath = "$($destDir)\solution.dff"
  85. $stream =  New-Object System.IO.StreamWriter($ddfFilePath);
  86. foreach($line in $lines){
  87.   $stream.WriteLine($line)
  88. }
  89.  
  90. foreach($file in $files){
  91.   $stream.WriteLine("`"$($destDir)\$($file)`" `"$($file)`"")
  92. }
  93.  
  94. $stream.Close()
  95.  
  96. set-location $destDir
  97. makecab.exe /F solution.dff
  98. Rename-Item ppp.cab "$($destWspFile)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement