Produced by Araxis Merge on 11/9/2018 12:16:34 PM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | RAMS-2.3.0.zip\RAMS-2.3.0\ps\module | RAMS_Module_Util.psm1 | Thu Aug 23 14:51:08 2018 UTC |
2 | RAMS-2.3.0.zip\RAMS-2.3.0\ps\module | RAMS_Module_Util.psm1 | Fri Nov 9 14:45:54 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 11 | 7422 |
Changed | 10 | 54 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | try { | ||
2 | Add-PSSnap in Microso ft.SharePo int.PowerS hell -Erro rAction Si lentlyCont inue | ||
3 | } | ||
4 | catch { | ||
5 | write-log -message "PSSnapin Microsoft. SharePoint .PowerShel l already loaded" -c onsoleFore ground Yel low | ||
6 | } | ||
7 | |||
8 | Set-Strict Mode -Vers ion Latest | ||
9 | |||
10 | if($env:CO MPUTERNAME -match "V APH" ) { | ||
11 | Add-Ty pe -Path . \RAMSUtil. dll | ||
12 | } | ||
13 | else { | ||
14 | Add-Ty pe -Path . .\UtilityS cripts\RAM SUtil.dll | ||
15 | } | ||
16 | |||
17 | function G et-FullHel p() { | ||
18 | <# | ||
19 | |||
20 | .SYNOP SIS | ||
21 | Di splay the help for a ll functio ns in this module. T he RAMS_Mo dule_Util contains r eusable Po werShell h elper func tions. | ||
22 | |||
23 | .DESCR IPTION | ||
24 | Di splays the Help for all functi ons in thi s module b y retrievi ng a list of functio ns and cal ling get-h elp for ea ch one. | ||
25 | Th e reusable helper fu nctions in the rest of the mod ule provid e a consis tent mecha nism for b uilding Sh arePoint | ||
26 | Si te Columns , Content Types, Lis ts, Views, Security Groups, an d more. It creates a repeatabl e process that provi des | ||
27 | co nsistency in develop ment. | ||
28 | |||
29 | .NOTES | ||
30 | Ea ch functio n in the m odule shou ld have it s own help . | ||
31 | |||
32 | .EXAMP LE | ||
33 | # Shows how to retriev e the help | ||
34 | Im port-Modul e .\module \RAMS_Modu le_Util.ps m1 | ||
35 | Ge t-FullHelp | ||
36 | |||
37 | .EXAMP LE | ||
38 | # Shows how to retriev e the help | ||
39 | Im port-Modul e .\module \RAMS_Modu le_Util.ps m1 | ||
40 | ge t-command -Module RA MS_Module_ Util | % { get-help $ _.name -fu ll } | ||
41 | |||
42 | .EXAMP LE | ||
43 | # Shows how to use oth er functio ns in the module | ||
44 | $P SModuleAut oLoadingPr eference | ||
45 | Re move-Modul e -Name RA MS_Module_ Util | ||
46 | Im port-Modul e .\module \RAMS_Modu le_Util.ps m1 | ||
47 | Ne w-RAMSEnv | ||
48 | Up date-RAMSE nv | ||
49 | |||
50 | Se t-Location .\Utility Scripts | ||
51 | Se t-Location .\module | ||
52 | New-Module Manifest - Path .\RAM S_Module_U til.psd1 - ModuleVers ion 1.2.0 -Author "C hita Nilak , ByLight" -RootModu le .\RAMS_ Module_Uti l.psm1 -De scription "RAMS Util ity Functi ons" -Comp anyName " DN S" -Verbos e | ||
53 | |||
54 | if ((Get-Modu le -Name R AMS_Module _Util) -ne $null) { | ||
55 | Remove-M odule -Nam e RAMS_Mod ule_Util | ||
56 | } | ||
57 | tr y { | ||
58 | Import-M odule .\RA MS_Module_ Util.psd1 | ||
59 | } catch { | ||
60 | Write-lo g -message "Host: $( $env:COMPU TERNAME) i s not a Se rver, Shar ePoint is not instal led on thi s computer ...ignore, informati on only." -ConsoleFo reground Y ellow | ||
61 | #do noth ing. | ||
62 | } | ||
63 | |||
64 | #> | ||
65 | |||
66 | get-co mmand -Mod ule RAMS_M odule_Util | % {get- help $_.na me -full } | ||
67 | } | ||
68 | |||
69 | function R emove-Cale ndarColumn s ([String []]$colLis t, $calTit le) { | ||
70 | <# | ||
71 | |||
72 | .SYNOP SIS | ||
73 | Re moves a li st of colu mns from a calendar list on al l subsites . | ||
74 | |||
75 | .DESCR IPTION | ||
76 | Fo r a given calendar a nd set of columns, l oop throug h the subs ites remov ing the co lumn from the calend ar. | ||
77 | |||
78 | .PARAM ETER colLi st | ||
79 | [S tring[]] A collectio n of site column sta tic names | ||
80 | |||
81 | .PARAM ETER calTi tle | ||
82 | [S tring] the title of the Calend ar List | ||
83 | |||
84 | .EXAMP LE | ||
85 | Re move-Calen darColumns -colList Attendees, Category -calTitle "SRS Calen dar" | ||
86 | |||
87 | #> | ||
88 | |||
89 | foreac h ($col in $colList) { | ||
90 | fo reach ($su bweb in (G et-SiteWeb ).Webs) { | ||
91 | $calLis t = $subwe b.Lists.Tr yGetList($ calTitle) | ||
92 | #remove column | ||
93 | if($cal List.Field s.TryGetFi eldByStati cName($col ) -ne $Nul l) { | ||
94 | $ca lList.Fiel ds.Delete( $col) | ||
95 | wri te-log -me ssage "$co l has been deleted f rom $subwe b : $calLi st" -Cons oleForegro und Yellow | ||
96 | $ca lList.Upda te() | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | } | ||
101 | |||
102 | function R unSQL-Retu rnInt ($sq lQuery,$db Server) { | ||
103 | <# | ||
104 | |||
105 | .SYNOP SIS | ||
106 | Ru ns a SQL s tatement a gainst the requested SQL Serve r database . | ||
107 | |||
108 | .DESCR IPTION | ||
109 | Th e function use Windo ws Authent ication fo r access t o the SQL database, it takes t wo argumen ts, both r equired, p lease refe r the exam ple to get more deta ils. | ||
110 | |||
111 | .PARAM ETER sqlQu ery | ||
112 | [S tring] A S QL query. | ||
113 | |||
114 | .PARAM ETER dbSer ver | ||
115 | [S tring] The URL of th e SQL Serv er instanc e. | ||
116 | |||
117 | .EXAMP LE | ||
118 | $c leanUpDate = "'05/30 /2017'" | ||
119 | $dbServer = " DNS . URL " | ||
120 | $q uery = "ex ec DataCle nup $clean UpDate" | ||
121 | $r esult = Ru nSQL-Retur nInt -sqlQ uery $quer y -dbServe r $dbServe r | ||
122 | wr ite-log -m essage "Nu mber of ro ws deleted : $result" -consoleF oreground Cyan | ||
123 | |||
124 | #> | ||
125 | |||
126 | $RAMSS QL = New-O bject Gov. VA.RAMS.RA MSUtil.Uti l | ||
127 | $RAMSS QL.SQLConn ectionStri ng = "Serv er=$dbServ er;Databas e=RAMS;Tru sted_Conne ction=Yes; " | ||
128 | $resul t = $RAMSS QL.RunSQL( $sqlQuery) | ||
129 | #close connectio n | ||
130 | if($RA MSSQL.SQLC onnection. State -ne "Closed") { | ||
131 | $R AMSSQL.Clo seSQLConne ction() | ||
132 | } | ||
133 | return $result | ||
134 | } | ||
135 | |||
136 | function R unSQL-Retu rnDR ($sql Query,$dbS erver) { | ||
137 | <# | ||
138 | |||
139 | .SYNOP SIS | ||
140 | Ru ns a SQL s tatement a gainst the requested SQL Serve r database . | ||
141 | |||
142 | .DESCR IPTION | ||
143 | Th e function use Windo ws Authent ication fo r access t o the SQL database, it takes t wo argumen ts, both r equired, p lease refe r the exam ple to get more deta ils. | ||
144 | |||
145 | .PARAM ETER sqlQu ery | ||
146 | [S tring] A S QL query. | ||
147 | |||
148 | .PARAM ETER dbSer ver | ||
149 | [S tring] The URL of th e SQL Serv er instanc e. | ||
150 | |||
151 | .EXAMP LE | ||
152 | $r esult = Ru nSQL-Retur nDR -sqlQu ery "selec t * from S tudies" -d bServer SE RVERNAME | ||
153 | |||
154 | #> | ||
155 | |||
156 | $RAMSS QL = New-O bject Gov. VA.RAMS.RA MSUtil.Uti l | ||
157 | $RAMSS QL.SQLConn ectionStri ng = "Serv er=$dbServ er;Databas e=RAMS;Tru sted_Conne ction=Yes; " | ||
158 | $dR = $RAMSSQL.R unSQLRestu rnDS($sqlQ uery) | ||
159 | return $dR | ||
160 | } | ||
161 | |||
162 | function G et-RAMSSha rePointIns tallInfo { | ||
163 | <# | ||
164 | .SYNOP SIS | ||
165 | Ve rify that the enviro nment to m ake sure i t meets ex pectations . | ||
166 | |||
167 | .DESCR IPTION | ||
168 | Ve rifies tha t the pers on running the scrip t is an ad ministrato r; that Sh arePoint P owerShell is loaded; and that SharePoint and Power Shell are what is ex pected. | ||
169 | |||
170 | .EXAMP LE | ||
171 | Ge t-RAMSShar ePointInst allInfo | ||
172 | |||
173 | .EXAMP LE | ||
174 | Ge t-RAMSShar ePointInst allInfo | Format-Tab le -AutoSi ze | ||
175 | |||
176 | .NOTES | ||
177 | Re quires Pow erShell Ve rsion 2.0 or Version 3.0 | ||
178 | Re quires to be execute d as an Ad ministrato r | ||
179 | |||
180 | .EXAMP LE | ||
181 | Ge t-RAMSShar ePointInst allInfo -V erbose | ||
182 | |||
183 | #> | ||
184 | [Cmdle tBinding() ] | ||
185 | Param( ) | ||
186 | |||
187 | Begin { | ||
188 | Wr ite-Verbos e "Enterin g Begin Bl ock" | ||
189 | |||
190 | if (-NOT ([S ecurity.Pr incipal.Wi ndowsPrinc ipal][Secu rity.Princ ipal.Windo wsIdentity ]::GetCurr ent()).IsI nRole([Sec urity.Prin cipal.Wind owsBuiltIn Role] "Adm inistrator ")) { | ||
191 | Write-Wa rning "You do not ha ve Adminis trator rig hts to run this scri pt!`nPleas e re-run t his script as an Adm inistrator !" | ||
192 | Exit | ||
193 | } else { | ||
194 | Write-Ve rbose "You are an Ad ministrato r. Continu e to Proce ss Block." | ||
195 | } | ||
196 | |||
197 | |||
198 | tr y { | ||
199 | $isSPPow erShellLoa ded = $nul l | ||
200 | $SPSnapi n = "Micro soft.Share Point.Powe rShell" | ||
201 | if (Get- PSSnapin $ SPSnapin - ErrorActio n Silently Continue) { | ||
202 | $isS PPowerShel lLoaded = $true | ||
203 | Writ e-Verbose "Microsoft .SharePoin t.PowerShe ll Snappin already r egistered and loaded " | ||
204 | } | ||
205 | elseif ( Get-PSSnap in $SPSnap in -Regist ered -Erro rAction Si lentlyCont inue) { | ||
206 | Add- PSSnapin $ SPSnapin | ||
207 | $isS PPowerShel lLoaded = $true | ||
208 | Writ e-Verbose "Microsoft .SharePoin t.PowerShe ll Snappin is regist ered and h as been lo aded for s cript oper ation" | ||
209 | } | ||
210 | else { | ||
211 | $isS PowerShell Loaded = $ false | ||
212 | Writ e-Warning "Microsoft .SharePoin t.PowerShe ll Snappin not found ." | ||
213 | Writ e-Warning "Will not be able to report Sh arePoint B uild Versi on" | ||
214 | } | ||
215 | |||
216 | } catch { | ||
217 | $isSPPow erShellLoa ded = $fal se | ||
218 | Write-Er ror "There was an is sue loadin g the Micr osoft.Shar ePoint.Pow erShell Sn appin. Scr ipt execut ion will c ontinue" | ||
219 | Write-Er ror $_ | ||
220 | Write-Wa rning "Wil l not be a ble to rep ort ShareP oint Build Version" | ||
221 | } | ||
222 | |||
223 | Wr ite-Verbos e "Leaving Begin Blo ck" | ||
224 | } | ||
225 | |||
226 | Proces s { | ||
227 | Wr ite-Verbos e "Enterin g Process Block" | ||
228 | |||
229 | Wr ite-Verbos e "Define SharePoint 2010 Prod ucts Regis try Path v ariable" | ||
230 | $R egPath2010 = "HKLM:\ SOFTWARE\M icrosoft\S hared Tool s\Web Serv er Extensi ons\14.0\W SS\Install edProducts \" | ||
231 | |||
232 | Wr ite-Verbos e "Define SharePoint 2010 Prod ucts hash table" | ||
233 | Wr ite-Verbos e "SharePo int 2010 S KU ID's fo und at htt p://msdn.m icrosoft.c om/en-us/l ibrary/ff7 21969(v=of fice.14).a spx" | ||
234 | $S P2010Produ cts = @{ | ||
235 | "B EED1F75-C3 98-4447-AE F1-E66E1F0 DF91E" = " SharePoint Foundatio n 2010" | ||
236 | "1 328E89E-7E C8-4F7E-80 9E-7E94579 6E511" = " Search Ser ver Expres s 2010" | ||
237 | "B 2C0B444-39 14-4ACB-A0 B8-7CF50A8 F7AA0" = " SharePoint Server 20 10 Standar d Trial" | ||
238 | "3 FDFBCC8-B3 E4-4482-91 FA-122C643 2805C" = " SharePoint Server 20 10 Standar d" | ||
239 | "8 8BED06D-8C 6B-4E62-AB 01-546D600 5FE97" = " SharePoint Server 20 10 Enterpr ise Trial" | ||
240 | "D 5595F62-44 9B-4061-B0 B2-0CBAD41 0BB51" = " SharePoint Server 20 10 Enterpr ise" | ||
241 | "B C4C1C97-90 13-4033-A0 DD-9DC9E6D 6C887" = " Search Ser ver 2010 T rial" | ||
242 | "0 8460AA2-A1 76-442C-BD CA-2692870 4D80B" = " Search Ser ver 2010" | ||
243 | "8 4902853-59 F6-4B20-BC 7C-DE4F419 FEFAD" = " Project Se rver 2010 Trial" | ||
244 | "E D21638F-97 FF-4A65-AD 9B-6889B93 065E2" = " Project Se rver 2010" | ||
245 | "9 26E4E17-08 7B-47D1-8B D7-91A394B C6196" = " Office Web Companion s 2010" | ||
246 | } | ||
247 | |||
248 | |||
249 | Wr ite-Verbos e "Define SharePoint 2013 Prod ucts Regis try Path v ariable" | ||
250 | $R egPath2013 = "HKLM:\ SOFTWARE\M icrosoft\S hared Tool s\Web Serv er Extensi ons\15.0\W SS\Install edProducts \" | ||
251 | |||
252 | Wr ite-Verbos e "Define SharePoint 2013 Prod ucts hash table" | ||
253 | Wr ite-Verbos e "SharePo int 2013 S KU ID's fo und at htt p://msdn.m icrosoft.c om/en-us/l ibrary/jj6 59075.aspx " | ||
254 | $S P2013Produ cts = @{ | ||
255 | "3 5466B1A-B1 7B-4DFB-A7 03-F74E2A1 F5F5E" = " Project Se rver 2013" | ||
256 | "B C7BAF08-4D 97-462C-84 11-3410524 02E71" = " Project Se rver 2013 Preview" | ||
257 | "C 5D855EE-F3 2B-4A1C-97 A8-F0A28CE 02F9C" = " SharePoint Server 20 13" | ||
258 | "C BF97833-C7 3A-4BAF-9E D3-D47B3CF F51BE" = " SharePoint Server 20 13 Preview " | ||
259 | "B 7D84C2B-07 54-49E4-B7 BE-7EE321D CE0A9" = " SharePoint Server 20 13 Enterpr ise" | ||
260 | "2 98A586A-E3 C1-42F0-AF E0-4BCFDC2 E7CD0" = " SharePoint Server 20 13 Enterpr ise Previe w" | ||
261 | "D 6B57A0D-AE 69-4A3E-B0 31-1F993EE 52EDC" = " Microsoft Office Web Apps Serv er 2013" | ||
262 | "9 FF54EBC-8C 12-47D7-85 4F-3865D4B E8118" = " SharePoint Foundatio n 2013" | ||
263 | } | ||
264 | |||
265 | Wr ite-Verbos e "Define function v ariables t o store da ta based o n current environmen t" | ||
266 | $R egPath = $ null | ||
267 | $S PProducts = $null | ||
268 | $S harePointV ersion = $ null | ||
269 | $C anProcess = $false | ||
270 | |||
271 | Wr ite-Verbos e "Test Re gistry Pat hs to dete rmine if c urrent env ironment h as SharePo int 2010 o r 2013 ins talled" | ||
272 | $i s2010 = Te st-Path $R egPath2010 | ||
273 | $i s2013 = Te st-Path $R egPath2013 | ||
274 | |||
275 | Wr ite-Verbos e "Populat e function variables with Shar ePoint ver sion speci fic data, if the env ironment c ontains Sh arePoint 2 010/2013" | ||
276 | if ($is2010) { | ||
277 | Write-Ve rbose "Sha rePoint 20 10 is inst alled" | ||
278 | $RegPath = $RegPat h2010 | ||
279 | $SPProdu cts = $SP2 010Product s | ||
280 | $SPVersi on = 2010 | ||
281 | $CanProc ess = $tru e | ||
282 | } elseif($is 2013) { | ||
283 | Write-Ve rbose "Sha rePoint 20 13 is inst alled" | ||
284 | $RegPath = $RegPat h2013 | ||
285 | $SPProdu cts = $SP2 013Product s | ||
286 | $SPVersi on = 2013 | ||
287 | $CanProc ess = $tru e | ||
288 | } else { | ||
289 | Write-Wa rning "Sha rePoint 20 10 or 2013 is not in stalled wi thin curre nt environ ment" | ||
290 | Write-Wa rning "Has h table in tended to store Shar ePoint Pro duct infor mation wil l be empty " | ||
291 | } | ||
292 | |||
293 | Wr ite-Verbos e "Define hash table to store installed SharePoint Product i nformation " | ||
294 | $I nstalledPr oducts = @ {} | ||
295 | |||
296 | Wr ite-Verbos e "Verify that curre nt environ ment is ho sting Shar ePoint 201 0 or 2013" | ||
297 | if ($CanProce ss) { | ||
298 | |||
299 | Write-Ve rbose "Det ermine whe ther the M icrosoft.S harePoint. PowerShell Snappin i s loaded" | ||
300 | if($isSP PowerShell Loaded) { | ||
301 | try { | ||
302 | Write-Verb ose "Get S harePoint Build Vers ion" | ||
303 | $SPBuildVe rsion = (G et-SPFarm) .BuildVers ion.ToStri ng() | ||
304 | |||
305 | Write-Verb ose "Addin g the Shar ePoint Bui ld Version to the In stalledPro ducts hash table" | ||
306 | $Installed Products.A dd("ShareP oint $SPVe rsion Buil d Version" ,$SPBuildV ersion) | ||
307 | } ca tch { | ||
308 | Write-Erro r "Unable to get the SharePoin t Build Ve rsion." | ||
309 | Write-Erro r $_ | ||
310 | } | ||
311 | } | ||
312 | |||
313 | Write-Ve rbose "Sha rePoint $S PVersion i s installe d within t he current environme nt" | ||
314 | Write-Ve rbose "Pop ulate Inst alledProdu cts hash t able with SharePoint Products installed on current environme nt" | ||
315 | Get-Item $RegPath | | ||
316 | Sele ct-Object -ExpandPro perty prop erty | | ||
317 | ForE ach-Object {(Get-Ite mProperty -Path $Reg Path -Name $_).$_} | | ||
318 | ForEach-Ob ject {$Ins talledProd ucts.Add($ SPProducts .Get_Item( $_),$_)} | ||
319 | } | ||
320 | |||
321 | Wr ite-Verbos e "Output the Instal ledProduct s hash tab le to pipe line." | ||
322 | Wr ite-Output $Installe dProducts | ||
323 | |||
324 | Wr ite-Verbos e "Leaving Process B lock" | ||
325 | } | ||
326 | } | ||
327 | |||
328 | function G et-SiteURL { | ||
329 | <# | ||
330 | |||
331 | .SYNOP SIS | ||
332 | Re turns the URL of the site coll ection | ||
333 | |||
334 | .DESCR IPTION | ||
335 | Lo ops throug h the Site Collectio ns looking for the o ne named I RBApplicat ions. | ||
336 | |||
337 | .EXAMP LE | ||
338 | $s iteUrl = G et-SiteURL | ||
339 | |||
340 | .EXAMP LE | ||
341 | $w eb = Get-S PWeb -Iden tity (Get- SiteURL) | ||
342 | |||
343 | .EXAMP LE | ||
344 | $G lobal:site Url = Get- SiteURL | ||
345 | |||
346 | #> | ||
347 | |||
348 | $site = Get-SPSi te -Limit All | Sele ct-String IRBApplica tions | ||
349 | $x = $ site.ToStr ing(); | ||
350 | $url = $x.Substr ing($x.Ind exOf("=")+ 1) | ||
351 | $w = G et-SPWeb $ url | ||
352 | return $url | ||
353 | } | ||
354 | |||
355 | function G et-MySiteU RL { | ||
356 | <# | ||
357 | |||
358 | .SYNOP SIS | ||
359 | Re turns the URL of the My Sites site colle ction | ||
360 | |||
361 | .DESCR IPTION | ||
362 | Lo ops throug h the Site Collectio ns looking for the o ne named M y Sites. | ||
363 | |||
364 | .EXAMP LE | ||
365 | $m ySiteUrl = Get-MySit eURL | ||
366 | |||
367 | .EXAMP LE | ||
368 | $w eb = Get-S PWeb -Iden tity (Get- MySiteURL) | ||
369 | |||
370 | .EXAMP LE | ||
371 | $G lobal:mySi teUrl = Ge t-MySiteUR L | ||
372 | |||
373 | #> | ||
374 | |||
375 | $site = get-spwe bapplicati on | selec t DisplayN ame, Url | ? { ($_.D isplayName -ilike "* My Site*") -or ($_.D isplayName -ilike "* MySite*") } | ||
376 | $url = $site.Url | ||
377 | $w = G et-SPWeb $ url | ||
378 | return $url | ||
379 | } | ||
380 | function G et-SiteWeb { | ||
381 | <# | ||
382 | |||
383 | .SYNOP SIS | ||
384 | Re turns the SPWeb for the Site C ollection | ||
385 | |||
386 | .DESCR IPTION | ||
387 | Ge ts the Sit eURL and t hen return s a SPWeb object for the site Collection . | ||
388 | |||
389 | .EXAMP LE | ||
390 | $w eb = Get-S iteWeb | ||
391 | |||
392 | .EXAMP LE | ||
393 | fo reach ($su bWeb in (G et-SiteWeb ).Webs) { ... } | ||
394 | |||
395 | .EXAMP LE | ||
396 | (G et-SiteWeb ).Webs | ||
397 | |||
398 | #> | ||
399 | |||
400 | $url = Get-SiteU RL | ||
401 | $xWeb = Get-Spwe b $url | ||
402 | return $xWeb | ||
403 | } | ||
404 | |||
405 | function G et-MySiteW eb { | ||
406 | <# | ||
407 | |||
408 | .SYNOP SIS | ||
409 | Re turns the SPWeb for the MySite Site Coll ection | ||
410 | |||
411 | .DESCR IPTION | ||
412 | Ge ts the Sit eURL and t hen return s a SPWeb object for the MySit e site Col lection. | ||
413 | |||
414 | .EXAMP LE | ||
415 | $w eb = Get-M ySiteWeb | ||
416 | |||
417 | .EXAMP LE | ||
418 | fo reach ($su bWeb in (G et-MySiteW eb).Webs) { ... } | ||
419 | |||
420 | .EXAMP LE | ||
421 | (G et-MySiteW eb).Webs | ||
422 | |||
423 | #> | ||
424 | |||
425 | $url = Get-MySit eURL | ||
426 | $xWeb = Get-Spwe b $url | ||
427 | return $xWeb | ||
428 | } | ||
429 | Function D eploy-Feat ure { | ||
430 | <# | ||
431 | |||
432 | .SYNOP SIS | ||
433 | De ploys a Wo rkflow Fea ture to th e site col lection. | ||
434 | |||
435 | .DESCR IPTION | ||
436 | Ad ds the SPU serSolutio n, Install s the SPUs erSolution , and then enables t he Feature . These st eps essent ially impo rt | ||
437 | th e workflow as featur e and then publish i t to the s ite collec tion or th e subsite. | ||
438 | |||
439 | .PARAM ETER SiteC ollection | ||
440 | [S tring] The site coll ection URL . | ||
441 | |||
442 | .PARAM ETER site | ||
443 | [S tring] The site the feature is to be pub lished to. | ||
444 | |||
445 | .PARAM ETER Featu reName | ||
446 | [S tring] The name of t he workflo w feature | ||
447 | |||
448 | .PARAM ETER OldFe atureId | ||
449 | [S tring] The Name of t he workflo w feature to remove. Must be p rovided, b ut not cur rently use d. | ||
450 | |||
451 | .PARAM ETER Featu reId | ||
452 | [S tring] The workflow' s feature id. | ||
453 | |||
454 | .PARAM ETER file | ||
455 | [S tring] The file name of the wo rkflow tem plate, inc luding the .wsp exte nsion. | ||
456 | |||
457 | .PARAM ETER bolUn install | ||
458 | [b ool] Indic ates if th e workflow should be uninstall ed. Must b e provided , but not currently used. | ||
459 | |||
460 | .PARAM ETER bolEn ableFeatur eOnly | ||
461 | [b ool] Once the workfl ow is inst alled, thi s indicato r tells th e script t o enable t he workflo w on subsi tes. | ||
462 | |||
463 | .EXAMP LE | ||
464 | De ploy-Featu re -SiteCo llection $ _siteURL - site $w.Ur l -Feature Name $feat ureTemplat eName -Old FeatureId $tempFeatu reId -Feat ureId $new FeatureId -file $scr ipt -bolUn install $u nInstall - bolEnableF eatureOnly $False | ||
465 | |||
466 | #> | ||
467 | |||
468 | |||
469 | Param( | ||
470 | [P arameter(M andatory=$ True)] | ||
471 | [s tring]$Sit eCollectio n, | ||
472 | |||
473 | [P arameter(M andatory=$ True)] | ||
474 | [s tring]$sit e, | ||
475 | |||
476 | [P arameter(M andatory=$ True)] | ||
477 | [s tring]$Fea tureName, | ||
478 | |||
479 | [P arameter(M andatory=$ True)] | ||
480 | [s tring]$Old FeatureId, | ||
481 | |||
482 | [P arameter(M andatory=$ True)] | ||
483 | [s tring]$Fea tureId, | ||
484 | |||
485 | [P arameter(M andatory=$ True)] | ||
486 | [s tring]$fil e, | ||
487 | |||
488 | [P arameter(M andatory=$ True)] | ||
489 | [b ool] $bolU ninstall, | ||
490 | |||
491 | [P arameter(M andatory=$ False)] | ||
492 | [b ool] $bolE nableFeatu reOnly | ||
493 | ) | ||
494 | |||
495 | |||
496 | Add-PS Snapin Mic rosoft.Sha rePoint.Po werShell | ||
497 | |||
498 | # GET THE SITE C OLLECTION | ||
499 | $SiteC ollectionw eb = Get-S PWeb $Site Collection | ||
500 | |||
501 | # GET THE SITE | ||
502 | $web = Get-SPWeb $site | ||
503 | |||
504 | # CLEA N and old one first | ||
505 | if($bo lEnableFea tureOnly - eq $False) { | ||
506 | <# | ||
507 | # All the ol d workflow s were uni nstalled i n a previo us step. T his is not needed at this time ,but may b e | ||
508 | # needed in future rel eases | ||
509 | if ($bolUnins tall) { | ||
510 | write-lo g -message " Uninst all old Fe ature $Fea tureName" -consoleFo reground G ray | ||
511 | |||
512 | write-lo g -message " Disa bling feat ure Identi ty $OldFea tureId URL $($web.Ur l)" -conso leForegrou nd Yellow | ||
513 | Disable- SPFeature -Identity $OldFeatur eId -Url $ SiteCollec tionweb.Ur l -Force - ErrorActio n Silently Continue | ||
514 | |||
515 | write-lo g -message " Unin stalling f eature Fea ture $Feat ureName Id entity $Fe atureName Site $($Si teCollecti onweb.Url) " -console Foreground Yellow | ||
516 | Uninstal l-SPUserSo lution -Id entity $Fe atureName -Site $Sit eCollectio nweb.Site | ||
517 | |||
518 | write-lo g -message " Remo ving featu re Feature $FeatureN ame Identi ty $Featur eName Site $($SiteCo llectionwe b.Url)" -c onsoleFore ground Yel low | ||
519 | Remove-S PUserSolut ion -Ident ity $Featu reName -Si te $SiteCo llectionwe b.Site | ||
520 | $web.Upd ate() | ||
521 | |||
522 | #remove from workf low manage r as well | ||
523 | Remove-W orkFlow -w fMatchName ($Feature Name.Repla ce(".wsp", "")) -wfWe b $web | ||
524 | } | ||
525 | #> | ||
526 | $s tatus = "S tart" | ||
527 | # ADD/UPLOAD TO THE SO LUTIONS | ||
528 | wr ite-log -m essage " Adding new Feature $ FeatureNam e Identity $FeatureI d Site $($ SiteCollec tionweb.Ur l)" -conso leForegrou nd Gray | ||
529 | tr y { | ||
530 | Add-SPUS erSolution -LiteralP ath $file -Site $Sit eCollectio nweb.Url - Verbose | ||
531 | $web.Upd ate() | ||
532 | write-lo g -message " Adde d Feature $FeatureNa me file $f ile Site $ ($SiteColl ectionweb. Url)" -con soleForegr ound Green | ||
533 | $status = "Added" | ||
534 | } catch { | ||
535 | write-lo g -message " Add- SPUserSolu tion Faile d to Add F eature $Fe atureName file $file Site $($S iteCollect ionweb.Url )" -Consol eForegroun d Red | ||
536 | } | ||
537 | if ($status -eq "Added ") { | ||
538 | # ACTIVA TE THE SOL UTION | ||
539 | write-lo g -message " Instal ling new F eature $Fe atureName Identity $ FeatureId Site $($Si teCollecti onweb.Url) " -console Foreground Gray | ||
540 | try { | ||
541 | Inst all-SPUser Solution - Identity $ FeatureNam e -Site $S iteCollect ionweb.Url | ||
542 | $web .Update() | ||
543 | writ e-log -mes sage " Install Fe ature $Fea tureName I dentity $F eatureId S ite $($Sit eCollectio nweb.Url)" -consoleF oreground Green | ||
544 | $sta tus = "Ins talled" | ||
545 | } catch { | ||
546 | write -log -mess age " I nstall-SPU serSolutio n Failed t o Install Feature $F eatureName Site $($S iteCollect ionweb.Url )" -Consol eForegroun d Red | ||
547 | } | ||
548 | } | ||
549 | } | ||
550 | if (($ bolEnableF eatureOnly -eq $True ) -or ($st atus -eq " Installed" )) { | ||
551 | # ENABLE THE FEATURE F OR THE GIV EN SITE | ||
552 | # feature id goes into -Identity | ||
553 | wr ite-log -m essage " Enabling n ew Feature $FeatureN ame Identi ty $Featur eId Url $( $web.Url)" -consoleF oreground Gray | ||
554 | tr y { | ||
555 | Enable-S PFeature - Identity $ FeatureId -Url $web. Url -Verbo se -Force | ||
556 | $web.Upd ate() | ||
557 | write-lo g -message " Enab led Featur e $Feature Name Ident ity $Featu reId Url $ ($web.Url) " -console Foreground Green | ||
558 | } catch { | ||
559 | write-lo g -message "Enable-S PFeature f ailed for Feature $F eatureName Identity $FeatureId Url $($we b.Url)" -C onsoleFore ground Red | ||
560 | } | ||
561 | } | ||
562 | } | ||
563 | |||
564 | Function D eploy-Farm ERFeature { | ||
565 | <# | ||
566 | |||
567 | .SYNOP SIS | ||
568 | De ploys a Fe ature to t he site co llection. | ||
569 | |||
570 | .DESCR IPTION | ||
571 | Ad ds the SPS olution, I nstalls th e SPSoluti on, and th en enables the Featu re. These steps esse ntially im port | ||
572 | th e workflow or event receiver a s feature and then p ublish it to the sit e collecti on or the subsite. | ||
573 | |||
574 | .PARAM ETER SiteC ollection | ||
575 | [S tring] The site coll ection URL . | ||
576 | |||
577 | .PARAM ETER site | ||
578 | [S tring] The site the feature is to be pub lished to. | ||
579 | |||
580 | .PARAM ETER Featu reName | ||
581 | [S tring] The name of t he workflo w feature | ||
582 | |||
583 | .PARAM ETER OldFe atureId | ||
584 | [S tring] The Name of t he workflo w feature to remove. Must be p rovided, b ut not cur rently use d. | ||
585 | |||
586 | .PARAM ETER Featu reId | ||
587 | [S tring] The workflow' s feature id. | ||
588 | |||
589 | .PARAM ETER file | ||
590 | [S tring] The file name of the wo rkflow tem plate, inc luding the .wsp exte nsion. | ||
591 | |||
592 | .PARAM ETER bolUn install | ||
593 | [b ool] Indic ates if th e workflow should be uninstall ed. Must b e provided , but not currently used. | ||
594 | |||
595 | .PARAM ETER bolEn ableFeatur eOnly | ||
596 | [b ool] Once the workfl ow is inst alled, thi s indicato r tells th e script t o enable t he workflo w on subsi tes. | ||
597 | |||
598 | .EXAMP LE | ||
599 | De ploy-FarmE RFeature - SiteCollec tion $_sit eURL -site $w.Url -F eatureName $featureT emplateNam e -OldFeat ureId $tem pFeatureId -FeatureI d $newFeat ureId -fil e $script -bolUninst all $unIns tall -bolE nableFeatu reOnly $Fa lse | ||
600 | |||
601 | #> | ||
602 | |||
603 | |||
604 | Param( | ||
605 | [P arameter(M andatory=$ True)] | ||
606 | [s tring]$Sit eCollectio n, | ||
607 | |||
608 | [P arameter(M andatory=$ True)] | ||
609 | [s tring]$sit e, | ||
610 | |||
611 | [P arameter(M andatory=$ True)] | ||
612 | [s tring]$Fea tureName, | ||
613 | |||
614 | [P arameter(M andatory=$ True)] | ||
615 | [s tring]$Old FeatureId, | ||
616 | |||
617 | [P arameter(M andatory=$ True)] | ||
618 | [s tring]$Fea tureId, | ||
619 | |||
620 | [P arameter(M andatory=$ True)] | ||
621 | [s tring]$fil e, | ||
622 | |||
623 | [P arameter(M andatory=$ True)] | ||
624 | [b ool] $bolU ninstall, | ||
625 | |||
626 | [P arameter(M andatory=$ False)] | ||
627 | [b ool] $bolE nableFeatu reOnly | ||
628 | ) | ||
629 | |||
630 | |||
631 | Add-PS Snapin Mic rosoft.Sha rePoint.Po werShell | ||
632 | |||
633 | # GET THE SITE C OLLECTION | ||
634 | $SiteC ollectionw eb = Get-S PWeb $Site Collection | ||
635 | |||
636 | # GET THE SITE | ||
637 | $web = Get-SPWeb $site | ||
638 | |||
639 | # CLEA N and old one first | ||
640 | if($bo lEnableFea tureOnly - eq $False) { | ||
641 | |||
642 | # All the ol d workflow s were uni nstalled i n a previo us step. T his is not needed at this time ,but may b e | ||
643 | # needed in future rel eases | ||
644 | if ($bolUnins tall) { | ||
645 | write-lo g -message " Uninst all old Fe ature $Fea tureName" -consoleFo reground G ray | ||
646 | |||
647 | write-lo g -message " Disa bling feat ure Identi ty $OldFea tureId URL $($web.Ur l)" -conso leForegrou nd Yellow | ||
648 | Disable- SPFeature -Identity $OldFeatur eId -Url $ SiteCollec tionweb.Ur l -Force - ErrorActio n Silently Continue | ||
649 | Start-Sl eep -secon ds 10 | ||
650 | |||
651 | write-lo g -message " Unin stalling f eature Fea ture $Feat ureName Id entity $Fe atureName Site $($Si teCollecti onweb.Url) " -console Foreground Yellow | ||
652 | Uninstal l-SPSoluti on -Identi ty $Featur eName | ||
653 | Start-Sl eep -secon ds 60 | ||
654 | |||
655 | write-lo g -message " Remo ving featu re Feature $FeatureN ame Identi ty $Featur eName Site $($SiteCo llectionwe b.Url)" -c onsoleFore ground Yel low | ||
656 | Remove-S PSolution -Identity $FeatureNa me -Force | ||
657 | Start-Sl eep -secon ds 10 | ||
658 | $web.Upd ate() | ||
659 | |||
660 | #remove from workf low manage r as well | ||
661 | #Remove- WorkFlow - wfMatchNam e ($Featur eName.Repl ace(".wsp" ,"")) -wfW eb $web | ||
662 | } | ||
663 | |||
664 | $s tatus = "S tart" | ||
665 | # ADD/UPLOAD TO THE SO LUTIONS | ||
666 | wr ite-log -m essage " Adding new Feature $ FeatureNam e Identity $FeatureI d Site $($ SiteCollec tionweb.Ur l)" -conso leForegrou nd Gray | ||
667 | tr y { | ||
668 | Add-SPSo lution -Li teralPath $file -Ver bose | ||
669 | Start-Sl eep -secon ds 10 | ||
670 | $web.Upd ate() | ||
671 | write-lo g -message " Adde d Feature $FeatureNa me file $f ile Site $ ($SiteColl ectionweb. Url)" -con soleForegr ound Green | ||
672 | $status = "Added" | ||
673 | } catch { | ||
674 | write-lo g -message " Add- SPSolution Failed to Add Featu re $Featur eName file $file Sit e $($SiteC ollectionw eb.Url)" - ConsoleFor eground Re d | ||
675 | if ($($_ .Exception .ErrorReco rd)) { wri te-log -me ssage "$($ _.Exceptio n.ErrorRec ord)" -con soleForegr ound Red } | ||
676 | if ($($_ .Exception .stacktrac e)) { writ e-log -mes sage "$($_ .Exception .stacktrac e)" -conso leForegrou nd Red } | ||
677 | if ($($_ .ScriptSta ckTrace)) { write-lo g -message "$($_.Scr iptStackTr ace)" -con soleForegr ound Red } | ||
678 | } | ||
679 | if ($status -eq "Added ") { | ||
680 | # ACTIVATE T HE SOLUTIO N | ||
681 | wr ite-log -m essage " Installing new Featu re $Featur eName Iden tity $Feat ureId Site $($SiteCo llectionwe b.Url)" -c onsoleFore ground Gra y | ||
682 | try { | ||
683 | Inst all-SPSolu tion -Iden tity $Feat ureName -G ACDeployme nt -Force | ||
684 | Star t-Sleep -s econds 60 | ||
685 | $web .Update() | ||
686 | writ e-log -mes sage " Install Fe ature $Fea tureName I dentity $F eatureId S ite $($Sit eCollectio nweb.Url)" -consoleF oreground Green | ||
687 | $sta tus = "Ins talled" | ||
688 | } catch { | ||
689 | write -log -mess age " I nstall-SPS olution Fa iled to In stall Feat ure $Featu reName Sit e $($SiteC ollectionw eb.Url)" - ConsoleFor eground Re d | ||
690 | if ( $($_.Excep tion.Error Record)) { write-log -message "$($_.Exce ption.Erro rRecord)" -consoleFo reground R ed } | ||
691 | if ( $($_.Excep tion.stack trace)) { write-log -message " $($_.Excep tion.stack trace)" -c onsoleFore ground Red } | ||
692 | if ( $($_.Scrip tStackTrac e)) { writ e-log -mes sage "$($_ .ScriptSta ckTrace)" -consoleFo reground R ed } | ||
693 | } | ||
694 | } | ||
695 | } | ||
696 | |||
697 | if (($ bolEnableF eatureOnly -eq $True ) -or ($st atus -eq " Installed" )) { | ||
698 | # ENABLE THE FEATURE F OR THE GIV EN SITE | ||
699 | # feature id goes into -Identity | ||
700 | wr ite-log -m essage " Enabling n ew Feature $FeatureN ame Identi ty $Featur eId Url $( $web.Url)" -consoleF oreground Gray | ||
701 | tr y { | ||
702 | Enable-S PFeature - Identity $ FeatureId -Verbose - Force -Url (get-Site URL) | ||
703 | Start-Sl eep -secon ds 60 | ||
704 | $web.Upd ate() | ||
705 | write-lo g -message " Enab led Featur e $Feature Name Ident ity $Featu reId Url $ ($web.Url) " -console Foreground Green | ||
706 | } catch { | ||
707 | write-lo g -message "Enable-S PFeature f ailed for Feature $F eatureName Identity $FeatureId Url $($we b.Url)" -C onsoleFore ground Red | ||
708 | if ($($_ .Exception .ErrorReco rd)) { wri te-log -me ssage "$($ _.Exceptio n.ErrorRec ord)" -con soleForegr ound Red } | ||
709 | if ($($_ .Exception .stacktrac e)) { writ e-log -mes sage "$($_ .Exception .stacktrac e)" -conso leForegrou nd Red } | ||
710 | if ($($_ .ScriptSta ckTrace)) { write-lo g -message "$($_.Scr iptStackTr ace)" -con soleForegr ound Red } | ||
711 | } | ||
712 | } | ||
713 | |||
714 | } | ||
715 | Function D eploy-Farm WFFeature { | ||
716 | <# | ||
717 | |||
718 | .SYNOP SIS | ||
719 | De ploys a Fe ature to t he site co llection. | ||
720 | |||
721 | .DESCR IPTION | ||
722 | Ad ds the SPS olution, I nstalls th e SPSoluti on, and th en enables the Featu re. These steps esse ntially im port | ||
723 | th e workflow or event receiver a s feature and then p ublish it to the sit e collecti on or the subsite. | ||
724 | |||
725 | .PARAM ETER SiteC ollection | ||
726 | [S tring] The site coll ection URL . | ||
727 | |||
728 | .PARAM ETER site | ||
729 | [S tring] The site the feature is to be pub lished to. | ||
730 | |||
731 | .PARAM ETER Featu reName | ||
732 | [S tring] The name of t he workflo w feature | ||
733 | |||
734 | .PARAM ETER OldFe atureId | ||
735 | [S tring] The Name of t he workflo w feature to remove. Must be p rovided, b ut not cur rently use d. | ||
736 | |||
737 | .PARAM ETER Featu reId | ||
738 | [S tring] The workflow' s feature id. | ||
739 | |||
740 | .PARAM ETER file | ||
741 | [S tring] The file name of the wo rkflow tem plate, inc luding the .wsp exte nsion. | ||
742 | |||
743 | .PARAM ETER bolUn install | ||
744 | [b ool] Indic ates if th e workflow should be uninstall ed. Must b e provided , but not currently used. | ||
745 | |||
746 | .PARAM ETER bolEn ableFeatur eOnly | ||
747 | [b ool] Once the workfl ow is inst alled, thi s indicato r tells th e script t o enable t he workflo w on subsi tes. | ||
748 | |||
749 | .EXAMP LE | ||
750 | De ploy-FarmW FFeature - SiteCollec tion $_sit eURL -site $w.Url -F eatureName $featureT emplateNam e -OldFeat ureId $tem pFeatureId -FeatureI d $newFeat ureId -fil e $script -bolUninst all $unIns tall -bolE nableFeatu reOnly $Fa lse | ||
751 | |||
752 | #> | ||
753 | |||
754 | |||
755 | Param( | ||
756 | [P arameter(M andatory=$ True)] | ||
757 | [s tring]$Sit eCollectio n, | ||
758 | |||
759 | [P arameter(M andatory=$ True)] | ||
760 | [s tring]$sit e, | ||
761 | |||
762 | [P arameter(M andatory=$ True)] | ||
763 | [s tring]$Fea tureName, | ||
764 | |||
765 | [P arameter(M andatory=$ True)] | ||
766 | [s tring]$Old FeatureId, | ||
767 | |||
768 | [P arameter(M andatory=$ True)] | ||
769 | [s tring]$Fea tureId, | ||
770 | |||
771 | [P arameter(M andatory=$ True)] | ||
772 | [s tring]$fil e, | ||
773 | |||
774 | [P arameter(M andatory=$ True)] | ||
775 | [b ool] $bolU ninstall, | ||
776 | |||
777 | [P arameter(M andatory=$ False)] | ||
778 | [b ool] $bolE nableFeatu reOnly | ||
779 | ) | ||
780 | |||
781 | |||
782 | Add-PS Snapin Mic rosoft.Sha rePoint.Po werShell | ||
783 | |||
784 | # GET THE SITE C OLLECTION | ||
785 | $SiteC ollectionw eb = Get-S PWeb $Site Collection | ||
786 | |||
787 | # GET THE SITE | ||
788 | $web = Get-SPWeb $site | ||
789 | |||
790 | # CLEA N and old one first | ||
791 | if($bo lEnableFea tureOnly - eq $False) { | ||
792 | |||
793 | # All the ol d workflow s were uni nstalled i n a previo us step. T his is not needed at this time ,but may b e | ||
794 | # needed in future rel eases | ||
795 | if ($bolUnins tall) { | ||
796 | write-lo g -message " Uninst all old Fe ature $Fea tureName" -consoleFo reground G ray | ||
797 | |||
798 | write-lo g -message " Disa bling feat ure Identi ty $OldFea tureId URL $($web.Ur l)" -conso leForegrou nd Yellow | ||
799 | Disable- SPFeature -Identity $OldFeatur eId -Url $ SiteCollec tionweb.Ur l -Force - ErrorActio n Silently Continue | ||
800 | Start-Sl eep -secon ds 10 | ||
801 | |||
802 | write-lo g -message " Unin stalling f eature Fea ture $Feat ureName Id entity $Fe atureName Site $($Si teCollecti onweb.Url) " -console Foreground Yellow | ||
803 | Uninstal l-SPSoluti on -Identi ty $Featur eName | ||
804 | Start-Sl eep -secon ds 60 | ||
805 | |||
806 | write-lo g -message " Remo ving featu re Feature $FeatureN ame Identi ty $Featur eName Site $($SiteCo llectionwe b.Url)" -c onsoleFore ground Yel low | ||
807 | Remove-S PSolution -Identity $FeatureNa me -Force | ||
808 | Start-Sl eep -secon ds 10 | ||
809 | $web.Upd ate() | ||
810 | |||
811 | #remove from workf low manage r as well | ||
812 | #Remove- WorkFlow - wfMatchNam e ($Featur eName.Repl ace(".wsp" ,"")) -wfW eb $web | ||
813 | } | ||
814 | |||
815 | $s tatus = "S tart" | ||
816 | # ADD/UPLOAD TO THE SO LUTIONS | ||
817 | wr ite-log -m essage " Adding new Feature $ FeatureNam e Identity $FeatureI d Site $($ SiteCollec tionweb.Ur l)" -conso leForegrou nd Gray | ||
818 | tr y { | ||
819 | Add-SPSo lution -Li teralPath $file -Ver bose | ||
820 | Start-Sl eep -secon ds 10 | ||
821 | $web.Upd ate() | ||
822 | write-lo g -message " Adde d Feature $FeatureNa me file $f ile Site $ ($SiteColl ectionweb. Url)" -con soleForegr ound Green | ||
823 | $status = "Added" | ||
824 | } catch { | ||
825 | write-lo g -message " Add- SPSolution Failed to Add Featu re $Featur eName file $file Sit e $($SiteC ollectionw eb.Url)" - ConsoleFor eground Re d | ||
826 | if ($($_ .Exception .ErrorReco rd)) { wri te-log -me ssage "$($ _.Exceptio n.ErrorRec ord)" -con soleForegr ound Red } | ||
827 | if ($($_ .Exception .stacktrac e)) { writ e-log -mes sage "$($_ .Exception .stacktrac e)" -conso leForegrou nd Red } | ||
828 | if ($($_ .ScriptSta ckTrace)) { write-lo g -message "$($_.Scr iptStackTr ace)" -con soleForegr ound Red } | ||
829 | } | ||
830 | if ($status -eq "Added ") { | ||
831 | # ACTIVATE T HE SOLUTIO N | ||
832 | wr ite-log -m essage " Installing new Featu re $Featur eName Iden tity $Feat ureId Site $($SiteCo llectionwe b.Url)" -c onsoleFore ground Gra y | ||
833 | try { | ||
834 | Inst all-SPSolu tion -Iden tity $Feat ureName -G ACDeployme nt -Force | ||
835 | Star t-Sleep -s econds 60 | ||
836 | $web .Update() | ||
837 | writ e-log -mes sage " Install Fe ature $Fea tureName I dentity $F eatureId S ite $($Sit eCollectio nweb.Url)" -consoleF oreground Green | ||
838 | $sta tus = "Ins talled" | ||
839 | } catch { | ||
840 | write -log -mess age " I nstall-SPS olution Fa iled to In stall Feat ure $Featu reName Sit e $($SiteC ollectionw eb.Url)" - ConsoleFor eground Re d | ||
841 | if ( $($_.Excep tion.Error Record)) { write-log -message "$($_.Exce ption.Erro rRecord)" -consoleFo reground R ed } | ||
842 | if ( $($_.Excep tion.stack trace)) { write-log -message " $($_.Excep tion.stack trace)" -c onsoleFore ground Red } | ||
843 | if ( $($_.Scrip tStackTrac e)) { writ e-log -mes sage "$($_ .ScriptSta ckTrace)" -consoleFo reground R ed } | ||
844 | } | ||
845 | } | ||
846 | } | ||
847 | |||
848 | if (($ bolEnableF eatureOnly -eq $True ) -or ($st atus -eq " Installed" )) { | ||
849 | # ENABLE THE FEATURE F OR THE GIV EN SITE | ||
850 | # feature id goes into -Identity | ||
851 | wr ite-log -m essage " Enabling n ew Feature $FeatureN ame Identi ty $Featur eId Url $( $web.Url)" -consoleF oreground Gray | ||
852 | tr y { | ||
853 | Enable-S PFeature - Identity $ FeatureId -Verbose - Force -Url (Get-Site URL) | ||
854 | Start-Sl eep -secon ds 60 | ||
855 | $web.Upd ate() | ||
856 | write-lo g -message " Enab led Featur e $Feature Name Ident ity $Featu reId Url $ ($web.Url) " -console Foreground Green | ||
857 | |||
858 | $taskLis t=$web.Lis ts["Workfl ow Tasks"] | ||
859 | $history List=$web. Lists["Wor kflow Hist ory"] | ||
860 | $ct=$web .ContentTy pes["Docum ent"] | ||
861 | $culture =New-Objec t System.G lobalizati on.Culture Info("en-U S") | ||
862 | $Feature BaseName = $FeatureN ame.replac e(".wsp"," ") | ||
863 | $wfTempl ate=$web.W orkflowTem plates.Get TemplateBy Name($Feat ureBaseNam e,$culture ) | ||
864 | |||
865 | if ($wfT emplate) { | ||
866 | $ass ociationWF =[Microsof t.SharePoi nt.Workflo w.SPWorkfl owAssociat ion]::Crea teListCont entTypeAss ociation($ wfTemplate , $Feature Name,$task List,$hist oryList) | ||
867 | $ass ociationWF .AllowManu al = $true ; | ||
868 | $ass ociationWF .AutoStart Change = $ true; | ||
869 | $ass ociationWF .AutoStart Create = $ true; | ||
870 | $ct. WorkflowAs sociations .Add($asso ciationWF) | ||
871 | $ct. UpdateWork flowAssoci ationsOnCh ildren($tr ue,$true,$ true,$fals e) | ||
872 | } else { | ||
873 | writ e-log -Mes sage " Una ble to fin d workflow template for $Featu reName" -C onsoleFore ground Red | ||
874 | } | ||
875 | } catch { | ||
876 | write-lo g -message "Enable-S PFeature f ailed for Feature $F eatureName Identity $FeatureId Url $($we b.Url)" -C onsoleFore ground Red | ||
877 | if ($($_ .Exception .ErrorReco rd)) { wri te-log -me ssage "$($ _.Exceptio n.ErrorRec ord)" -con soleForegr ound Red } | ||
878 | if ($($_ .Exception .stacktrac e)) { writ e-log -mes sage "$($_ .Exception .stacktrac e)" -conso leForegrou nd Red } | ||
879 | if ($($_ .ScriptSta ckTrace)) { write-lo g -message "$($_.Scr iptStackTr ace)" -con soleForegr ound Red } | ||
880 | } | ||
881 | } | ||
882 | } | ||
883 | |||
884 | function A dd-SiteCol umnToCTByT itle ([Mic rosoft.Sha rePoint.SP SecurableO bject]$web , [String] $ctName,[S tring]$sFi eldTitle) { | ||
885 | <# | ||
886 | |||
887 | .SYNOP SIS | ||
888 | Ad ds a site column to a contentT ype. | ||
889 | |||
890 | .DESCR IPTION | ||
891 | Ge ts the con tent type from the s pweb objec t. Looks u p the site column by display n ame. If th e content type | ||
892 | do es not alr eady have the site c olumn it i s added an d pushed t o all subs ites and l ists that use the co ntent type . | ||
893 | |||
894 | .PARAM ETER web | ||
895 | [M icrosoft.S harePoint. SPSecurabl eObject] a web objec t that rep resents th e site col lection. | ||
896 | |||
897 | .PARAM ETER ctNam e | ||
898 | [S tring] The name of t he content type. | ||
899 | |||
900 | .PARAM ETER sFiel dTitle | ||
901 | [S tring] The display n ame of the site colu mn. | ||
902 | |||
903 | .EXAMP LE | ||
904 | $f ldTmp = $n ewDelegate dCommitee + ' Delega ted' | ||
905 | Ad d-SiteColu mnToCTByTi tle -web $ webSite -c tName "Com mittee CT" -sFieldTi tle $fldTm p | ||
906 | |||
907 | #> | ||
908 | |||
909 | $ct = $web.Conte ntTypes[$c tName]; | ||
910 | $field =$web.Fiel ds.GetFiel d($sFieldT itle) | ||
911 | $sFiel dStaticNam e = $field .StaticNam e | ||
912 | |||
913 | if(!$c t.Fields.C ontainsFie ldWithStat icName($sF ieldStatic Name)){ | ||
914 | $l ink = new- object Mic rosoft.Sha rePoint.SP FieldLink $field | ||
915 | #c heck if co mments fie lds exist or not. | ||
916 | if (($ct.Fiel dLinks | W here-Objec t {$_.Name -eq $fiel d.Internal Name}) -EQ $null) { | ||
917 | $ct.Fiel dLinks.Add ($link) | ||
918 | $ct.Upda te($true) | ||
919 | write-lo g -message "$sFieldT itle Field has been added to $ ct" -Conso leForegrou nd Green | ||
920 | } | ||
921 | el se { | ||
922 | write-lo g -message "$sFieldT itle Field already e xist" -Con soleForegr ound Yello w | ||
923 | } | ||
924 | } | ||
925 | } | ||
926 | |||
927 | function A dd-SiteCol umnToCT ([ Microsoft. SharePoint .SPSecurab leObject]$ web, [Stri ng]$ctName ,[String]$ sFieldInte rnalName, [String]$s FieldStati cName) { | ||
928 | <# | ||
929 | |||
930 | .SYNOP SIS | ||
931 | Ad ds a site column to a contentT ype. | ||
932 | |||
933 | .DESCR IPTION | ||
934 | Ge ts the con tent type from the s pweb objec t. Looks u p the site column by display n ame. If th e content type | ||
935 | do es not alr eady have the site c olumn it i s added an d pushed t o all subs ites and l ists that use the co ntent type . | ||
936 | |||
937 | .PARAM ETER web | ||
938 | [M icrosoft.S harePoint. SPSecurabl eObject] a web objec t that rep resents th e site col lection. | ||
939 | |||
940 | .PARAM ETER ctNam e | ||
941 | [S tring] The name of t he content type. | ||
942 | |||
943 | .PARAM ETER sFiel dInternalN ame | ||
944 | [S tring] The internal name of th e site col umn. | ||
945 | |||
946 | .PARAM ETER sFiel dStaticNam e | ||
947 | [S tring] The static na me of the site colum n. | ||
948 | |||
949 | .EXAMP LE | ||
950 | Ad d-SiteColu mnToCT -we b $webSite -ctName " Applicatio n CT" -sFi eldInterna lName "CIR B_ID" -sFi eldStaticN ame "CIRB_ ID" | ||
951 | |||
952 | #> | ||
953 | |||
954 | $ct = $web.Conte ntTypes[$c tName]; | ||
955 | if(!$c t.Fields.C ontainsFie ldWithStat icName($sF ieldStatic Name)){ | ||
956 | $f ield=$web. Fields.Try GetFieldBy StaticName ($sFieldSt aticName) | ||
957 | $l ink = new- object Mic rosoft.Sha rePoint.SP FieldLink $field | ||
958 | #c heck if co mments fie lds exist or not. | ||
959 | if (($ct.Fiel dLinks | W here-Objec t {$_.Name -eq $sFie ldInternal Name}) -EQ $null) { | ||
960 | $ct.Fiel dLinks.Add ($link) | ||
961 | $ct.Upda te($true) | ||
962 | write-lo g -message "$sFieldI nternalNam e Field ha s been add ed to $($c t.Name) Co ntent Type " -console Foreground Green | ||
963 | } | ||
964 | el se { | ||
965 | write-lo g -message "$sFieldI nternalNam e Field al ready exis t in $($ct .Name) Con tent Type" -consoleF oreground Yellow | ||
966 | } | ||
967 | } | ||
968 | } | ||
969 | |||
970 | function S et-SiteCol umn([Micro soft.Share Point.SPSe curableObj ect]$web, [String]$s FieldDispl ayName,[St ring]$sFie ldStaticNa me, [Strin g]$sFieldI nternalNam e, [Micros oft.ShareP oint.SPFie ldType]$sF ieldType, [System.Co llections. Specialize d.StringCo llection] $sChoice, [String]$s pFieldGrou p, [switch ] $isRequi red, [swit ch] $showI nEditForm, [switch] $showInNew Form, [swi tch] $allo wMultipleV alues, [St ring]$defa ultValue) { | ||
971 | <# | ||
972 | |||
973 | .SYNOP SIS | ||
974 | Ad ds a site column to a site col lection. | ||
975 | |||
976 | .DESCR IPTION | ||
977 | Ge ts the con tent type from the s pweb objec t. Looks u p the site column by display n ame. If th e content type | ||
978 | do es not alr eady have the site c olumn it i s added an d pushed t o all subs ites and l ists that use the co ntent type . | ||
979 | |||
980 | .PARAM ETER web | ||
981 | [M icrosoft.S harePoint. SPSecurabl eObject] a web objec t that rep resents th e site col lection. | ||
982 | |||
983 | .PARAM ETER sFiel dDisplayNa me | ||
984 | [S tring] The display n ame of the site colu mn. This s hould be a s it shoul d be displ ayed and i t can cont ain spaces . | ||
985 | |||
986 | .PARAM ETER sFiel dStaticNam e | ||
987 | [S tring] The static na me of the site colum n. This sh ould be th e same as the intern al name fo r consiste ncy. This should be the same a s the disp lay name, but withou t spaces. | ||
988 | |||
989 | .PARAM ETER sFiel dInternalN ame | ||
990 | [S tring] The internal name of th e site col umn. This should be the same a s the inte rnal name for consis tency. Thi s should b e the same as the di splay name , but with out spaces . | ||
991 | |||
992 | .PARAM ETER $sFie ldType, | ||
993 | [M icrosoft.S harePoint. SPFieldTyp e] The typ e of field to create . https:// msdn.micro soft.com/e n-us/libra ry/microso ft.sharepo int.spfiel dtype.aspx | ||
994 | |||
995 | .PARAM ETER $sCho ice, | ||
996 | [S ystem.Coll ections.Sp ecialized. StringColl ection] Pr ovides the Choice va lues that will be se t in the n ew choice site colum n. | ||
997 | |||
998 | .PARAM ETER $spFi eldGroup, | ||
999 | [S tring] Spe cifies whi ch Field G roup the s ite column should be added to. | ||
1000 | |||
1001 | .PARAM ETER $isRe quired, | ||
1002 | [s witch] Ind icates if the site c olumn is r equired. | ||
1003 | |||
1004 | .PARAM ETER $show InEditForm , | ||
1005 | [s witch] Ind icates if the site c olumn shou ld be adde d to the E dit Item F orm | ||
1006 | |||
1007 | .PARAM ETER $show InNewForm, | ||
1008 | [s witch] Ind icates if the site c olumn shou ld be adde d to the N ew Item Fo rm | ||
1009 | |||
1010 | .PARAM ETER $allo wMultipleV alues, | ||
1011 | [s witch] For People or Group fie lds indica tes if mul tiple peop le can be selected o r only one . | ||
1012 | |||
1013 | .PARAM ETER $defa ultValue | ||
1014 | [S tring] Opt ional. Set s the defa ult value for the ne w field. D o not use for Person or Group Fields. | ||
1015 | |||
1016 | .EXAMP LE | ||
1017 | Se t-SiteColu mn -web (G et-SiteWeb ) -sFieldD isplayName "Triennia l Review Date" -sFi eldStaticN ame "Trien nialReview Date" -sFi eldInterna lName "Tri ennialRevi ewDate" -s FieldType DateTime -spFieldGr oup "RAMS IRB" -show InEditForm -showInNe wForm | ||
1018 | |||
1019 | .EXAMP LE | ||
1020 | Se t-SiteColu mn -web (G et-SiteWeb ) -sFieldD isplayName $scDN -sF ieldStatic Name $scIN -sFieldIn ternalName $scIN -sF ieldType $ scType -s pFieldGrou p "RAMS IR B" -showIn EditForm - showInNewF orm -allow MultipleVa lues | ||
1021 | |||
1022 | .EXAMP LE | ||
1023 | Se t-SiteColu mn -web $w ebSite -sF ieldDispla yName "Adv erse Repor table Even t" -sField StaticName "AdverseR eportableE vent" -sFi eldInterna lName "Adv erseReport ableEvent" -sFieldTy pe "Text" -spFieldG roup "RAMS IRB" | ||
1024 | |||
1025 | #> | ||
1026 | |||
1027 | $web = (Get-Site Web) | ||
1028 | if (!$ web.Fields .ContainsF ieldWithSt aticName($ sFieldStat icName)){ | ||
1029 | $s FieldDispl ayName=$sF ieldDispla yName | ||
1030 | write-lo g -message "Adding t he field $ sFieldDisp layName to the Site" -consoleF oreground cyan | ||
1031 | $sFieldS taticName = $web.Fie lds.Add($s FieldInter nalName,$s FieldType, $false, $ false, $sC hoice); | ||
1032 | $spField =$web.Fiel ds.TryGetF ieldByStat icName($sF ieldStatic Name) | ||
1033 | $spField .Group= $s pFieldGrou p | ||
1034 | $spField .Title=$sF ieldDispla yName | ||
1035 | if($allo wMultipleV alues) { | ||
1036 | $spF ield.Allow MultipleVa lues = $Tr ue | ||
1037 | } | ||
1038 | if($defa ultValue) { | ||
1039 | if($ defaultVal ue -eq "tr ue" -or $d efaultValu e -eq "$tr ue" -or $d efaultValu e -eq "1") { | ||
1040 | $spField.D efaultValu e = "1" | ||
1041 | } el seif($defa ultValue - eq "false" -or $defa ultValue - eq "$false " -or $def aultValue -eq "0") { | ||
1042 | $spField.D efaultValu e = "0" | ||
1043 | } el se { | ||
1044 | $spField.D efaultValu e = $defau ltValue | ||
1045 | } | ||
1046 | } | ||
1047 | if($isRe quired) {$ spField.Re quired = $ True} | ||
1048 | if($show InEditForm ) {$spFiel d.ShowInEd itForm = $ True} | ||
1049 | if($show InNewForm) {$spField .ShowInNew Form = $Tr ue} | ||
1050 | |||
1051 | $spField .Update() | ||
1052 | } | ||
1053 | else { | ||
1054 | w rite-log - message "$ sFieldInte rnalName F ield alrea dy exist" -ConsoleFo reground Y ellow | ||
1055 | } | ||
1056 | } | ||
1057 | |||
1058 | function S et-SiteCol umnLookup( [Microsoft .SharePoin t.SPSecura bleObject] $web, [Str ing]$sFiel dStaticNam e, [String ]$sFieldDi splayName, [String]$ lookupList Title, [St ring]$spFi eldGroup) { | ||
1059 | <# | ||
1060 | |||
1061 | .SYNOP SIS | ||
1062 | Ad ds a looku p site col umn to a s ite collec tion. | ||
1063 | |||
1064 | .DESCR IPTION | ||
1065 | If the looku p column d oes not al ready exis t it is ad ded using Fields.Add Lookup. | ||
1066 | |||
1067 | .PARAM ETER web | ||
1068 | [M icrosoft.S harePoint. SPSecurabl eObject] a web objec t that rep resents th e site col lection. | ||
1069 | |||
1070 | .PARAM ETER sFiel dStaticNam e | ||
1071 | [S tring] The static na me of the site colum n. This sh ould be th e same as the intern al name fo r consiste ncy. This should be the same a s the disp lay name, but withou t spaces. | ||
1072 | |||
1073 | .PARAM ETER sFiel dDisplayNa me | ||
1074 | [S tring] The display n ame of the site colu mn. This s hould be a s it shoul d be displ ayed and i t can cont ain spaces . | ||
1075 | |||
1076 | .PARAM ETER looku pListTitle | ||
1077 | [S tring] The name of t he list th at is the source for the looku p. | ||
1078 | |||
1079 | .PARAM ETER $spFi eldGroup, | ||
1080 | [S tring] Spe cifies whi ch Field G roup the s ite column should be added to. | ||
1081 | |||
1082 | .EXAMP LE | ||
1083 | Se t-SiteColu mnLookup - web $web - colName "F acilities Lookup" -c olStaticNa me "Facili tiesLookup " -lookupL istName "F acilities" -lookupCo lumnName " Title" | ||
1084 | |||
1085 | .EXAMP LE | ||
1086 | Se t-SiteColu mnLookup - web $web - colName "D elegated" -colStatic Name "Dele gated" -lo okupListNa me "Facili ties" -loo kupColumnN ame "Title " | ||
1087 | |||
1088 | #> | ||
1089 | |||
1090 | if (!$ web.Fields .ContainsF ieldWithSt aticName($ sFieldStat icName)){ | ||
1091 | write-lo g -message "Adding t he field $ sFieldDisp layName to the Site" -consoleF oreground cyan | ||
1092 | $sFieldS taticName = $web.Fie lds.AddLoo kup($sFiel dDisplayNa me,(($web. Lists.TryG etList($lo okupListTi tle)).Id), $false) | ||
1093 | $spField =$web.Fiel ds.TryGetF ieldByStat icName($sF ieldStatic Name) | ||
1094 | $spField .Group= $s pFieldGrou p | ||
1095 | $spField .Title=$sF ieldDispla yName | ||
1096 | $spField .Update() | ||
1097 | } | ||
1098 | else { | ||
1099 | w rite-log - message "$ sFieldInte rnalName F ield alrea dy exist" -ConsoleFo reground Y ellow | ||
1100 | } | ||
1101 | } | ||
1102 | |||
1103 | function U pdate-Site ColumnLook up ([Micro soft.Share Point.SPSe curableObj ect]$web,$ siteColumn Title,$loo kupListTit le,$lookup ListFieldT itle){ | ||
1104 | <# | ||
1105 | |||
1106 | .SYNOP SIS | ||
1107 | Ch anges the source of the Lookup site colu mn. | ||
1108 | |||
1109 | .DESCR IPTION | ||
1110 | Fi nds the lo okup field , gets the new looku p table, a nd sets th e lookup f ield site columns to the Id an d lookupLi stFieldTit le. All er rors are d isplayed t o the user . | ||
1111 | |||
1112 | .PARAM ETER web | ||
1113 | [M icrosoft.S harePoint. SPSecurabl eObject] a web objec t that rep resents th e site col lection. | ||
1114 | |||
1115 | .PARAM ETER siteC olumnTitle | ||
1116 | [S tring] the site colu mn display name. | ||
1117 | |||
1118 | .PARAM ETER looku pListTitle | ||
1119 | [S tring] The static na me of the site colum n. This sh ould be th e same as the intern al name fo r consiste ncy. This should be the same a s the disp lay name, but withou t spaces. | ||
1120 | |||
1121 | .PARAM ETER looku pListField Title | ||
1122 | [S tring] The display n ame of the site colu mn. This s hould be a s it shoul d be displ ayed and i t can cont ain spaces . | ||
1123 | |||
1124 | .EXAMPL E | ||
1125 | NO T USED in RAMS-2.3.0 | ||
1126 | |||
1127 | #> | ||
1128 | |||
1129 | #$web = Get-SPWe b $webURL | ||
1130 | #$site ColumnFld = ($web.Fi elds | ? { $_.Title - match $sit eColumnTit le}) | ||
1131 | $siteC olumnFld = $web.Fiel ds.TryGetF ieldByStat icName($si teColumnTi tle) | ||
1132 | $listL ookup = $w eb.Lists.T ryGetList( $lookupLis tTitle) | ||
1133 | # unfo rtunately, you can't change th e source l ist of a l ookup site column. I f the list is the sa me and you are | ||
1134 | # chan ging the f ield, that is ok. | ||
1135 | #$site ColumnFld. LookupList = $listLo okup.ID | ||
1136 | $siteC olumnFld.L ookupField = $lookup ListFieldT itle | ||
1137 | $siteC olumnFld.U pdate() | ||
1138 | $web.d ispose() | ||
1139 | } | ||
1140 | |||
1141 | function A dd-Facilit yWorkflow ($featureT emplateNam e, $newFea tureId, $o ldFeatureI d, $search Display, $ listName, $unInstall ){ | ||
1142 | <# | ||
1143 | |||
1144 | .SYNOP SIS | ||
1145 | Ad ds a workf low at the facility level, for each faci lity subwe b to the l ist config ured in th e workflow . | ||
1146 | |||
1147 | .DESCR IPTION | ||
1148 | Lo ops throug h each sub site spweb and calls DeployFea ture passi ng the inc oming para meters. | ||
1149 | |||
1150 | .PARAM ETER featu reTemplate Name | ||
1151 | [S tring] The name of t he WSP wor kflow temp late file with the . wsp extens ion added. | ||
1152 | |||
1153 | .PARAM ETER newFe atureId | ||
1154 | [S tring] The featureID GUID from inside th e wsp file . | ||
1155 | |||
1156 | .PARAM ETER oldFe atureId | ||
1157 | [S tring] The name or t he old Fea ture Id (g uid) of th e workflow that shou ld be dele ted or rep laced by t he new Wor kflow. | ||
1158 | |||
1159 | .PARAM ETER searc hDisplay | ||
1160 | [S tring] The name of t he WSP wor kflow temp late file without th e .wsp ext ension. | ||
1161 | |||
1162 | .PARAM ETER listN ame | ||
1163 | [S tring] The List Name that the workflow w ill be ass ociated to . | ||
1164 | |||
1165 | .PARAM ETER unIns tall | ||
1166 | [b oolean] In dicates if the workf low should be uninst alled. | ||
1167 | |||
1168 | .EXAMPL E | ||
1169 | # This examp le reads a list of w orkflows f rom WfList .csv file that conta in the New Workflow Name, New Feature Id , Old Work flow Name, the List Name, and IsFacility Level | ||
1170 | # and based on the IsF acility Le vel calls Add-Facili tyWorkflow or Add-Si teCollecti onWorkFlow | ||
1171 | if ($wfType -eq "Facil ityList") { | ||
1172 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1173 | Add-Faci lityWorkfl ow -featur eTemplateN ame "$($ne wWfName).w sp" -newFe atureId $n ewFeatureI d -searchD isplay $ne wWfName -o ldFeatureI d $oldFeat ureId -lis tName $tar getName -u nInstall $ False | ||
1174 | } elseif (($ wfType -eq "SiteList ") -or (($ wfType -eq "Site"))) { | ||
1175 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1176 | Add-Site Collection WorkFlow - featureTem plateName "$($newWfN ame).wsp" -newFeatur eId $newFe atureId -s earchDispl ay $newWfN ame -oldFe atureId $o ldFeatureI d -unInsta ll $False | ||
1177 | } elseif ($w fType -eq "SiteWFCon tentTypeAs sociation" ) { | ||
1178 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1179 | Add-Reus ableWorkFl owToConten tType -fea tureTempla teName "$( $newWfName ).wsp" -ne wFeatureId $newFeatu reId -sear chDisplay $newWfName -oldFeatu reId $oldF eatureId - contentTyp eName $tar getName -u nInstall $ False | ||
1180 | } elseif ($w fType -eq "SiteEvent Receiver") { | ||
1181 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1182 | Add-Even tReceiverT oContentTy pe -featur eTemplateN ame "$($ne wWfName).w sp" -newFe atureId $n ewFeatureI d -searchD isplay $ne wWfName -o ldFeatureI d $OldWFNa me -conten tTypeName $targetNam e -unInsta ll $False | ||
1183 | } else { | ||
1184 | write-lo g -message "ERROR: U nknown wfT ype: wfTyp e: $($wfTy pe)" -cons oleForegro und Red -L evel "ERRO R" | ||
1185 | } | ||
1186 | #> | ||
1187 | |||
1188 | $bolEn ableFeatur eOnly = $F alse #init ialize | ||
1189 | # GET THE SITE | ||
1190 | $_site URL = Get- SiteURL | ||
1191 | $w = G et-SPWeb $ _siteURL | ||
1192 | |||
1193 | write- log -messa ge "$([Str ing]::Form at("Proces ing web {0 }",$w.Url) )" -Consol eForegroun d Cyan | ||
1194 | |||
1195 | if($w. Webs.Count -gt 0) | ||
1196 | { | ||
1197 | fo reach($web in $w.Web s) | ||
1198 | { | ||
1199 | #TAR Rem ove Featur es in prev ious steps | ||
1200 | #Enable old workfl ows from 2 .1 or befo re | ||
1201 | #if($old FeatureNam e -contain s "*IACUC* " -or $old FeatureNam e -contain s "*RDC*") { | ||
1202 | # Ena ble-SPFeat ure -Ident ity $oldFe atureName -Url $web. Url -Verbo se -Force | ||
1203 | # Ena ble-SPFeat ure -Ident ity $oldFe atureName -Url $site Url -Verbo se -Force | ||
1204 | #} | ||
1205 | #$web.Up date() | ||
1206 | #get abo ve old wor kflows | ||
1207 | $Oldfeat ure = $nul l #initial ize | ||
1208 | |||
1209 | if($bolE nableFeatu reOnly -eq $False) { | ||
1210 | try { | ||
1211 | $Oldfeatur e = Get-SP Feature -I dentity $o ldFeatureI d -Web $_s iteURL -Er rorAction Ignore -Ve rbose | ||
1212 | } | ||
1213 | catc h { | ||
1214 | write-log -message " Feature: $ oldFeature Id does no t exist fo r Site: $w eb.Url" -C onsoleFore ground Red | ||
1215 | } | ||
1216 | } | ||
1217 | $tempFea tureId = $ null | ||
1218 | if($Oldf eature -ne $null) { | ||
1219 | $tem pFeatureId = $Oldfea ture.Id | ||
1220 | } | ||
1221 | if ($tem pFeatureId -eq $null ) | ||
1222 | { | ||
1223 | $tem pFeatureId = $newFea tureId | ||
1224 | } | ||
1225 | write-lo g -message "Calling Deploy-Fea ture on $w eb with $f eatureTemp lateName O ldFeatureI d $tempFea tureId Fea tureId $ne wFeatureId " -Consol eForegroun d Gray | ||
1226 | if($bolE nableFeatu reOnly -eq $False) { | ||
1227 | Depl oy-Feature -SiteColl ection $_s iteURL -si te $web.Ur l -Feature Name $feat ureTemplat eName -Old FeatureId $tempFeatu reId -Feat ureId $new FeatureId -file $scr ipt -bolUn install $u nInstall - bolEnableF eatureOnly $bolEnabl eFeatureOn ly | ||
1228 | $bol EnableFeat ureOnly = $True | ||
1229 | } | ||
1230 | else { | ||
1231 | Depl oy-Feature -SiteColl ection $_s iteURL -si te $web.Ur l -Feature Name $feat ureTemplat eName -Old FeatureId $tempFeatu reId -Feat ureId $new FeatureId -file $scr ipt -bolUn install $u nInstall - bolEnableF eatureOnly $bolEnabl eFeatureOn ly | ||
1232 | } | ||
1233 | } | ||
1234 | } | ||
1235 | } | ||
1236 | |||
1237 | function A dd-SiteCol lectionWor kFlow ($fe atureTempl ateName, $ newFeature Id, $oldFe atureId, $ searchDisp lay, $unIn stall) { | ||
1238 | <# | ||
1239 | |||
1240 | .SYNOP SIS | ||
1241 | Ad ds a workf low at the site coll ection lev el to the site itsel f or the l ist config ured in th e workflow . | ||
1242 | |||
1243 | .DESCR IPTION | ||
1244 | Ca lls Deploy Feature pa ssing the incoming p arameters. | ||
1245 | |||
1246 | .PARAM ETER featu reTemplate Name | ||
1247 | [S tring] The name of t he WSP wor kflow temp late file with the . wsp extens ion added. | ||
1248 | |||
1249 | .PARAM ETER newFe atureId | ||
1250 | [S tring] The featureID GUID from inside th e wsp file . | ||
1251 | |||
1252 | .PARAM ETER oldFe atureName | ||
1253 | [S tring] The name of t he workflo w that sho uld be del eted or re placed by the new Wo rkflow. | ||
1254 | |||
1255 | .PARAM ETER searc hDisplay | ||
1256 | [S tring] The name of t he WSP wor kflow temp late file without th e .wsp ext ension. | ||
1257 | |||
1258 | .PARAM ETER unIns tall | ||
1259 | [b oolean] In dicates if the workf low should be uninst alled. | ||
1260 | |||
1261 | .EXAMPL E | ||
1262 | # This examp le reads a list of w orkflows f rom WfList .csv file that conta in the New Workflow Name, New Feature Id , Old Work flow Name, the List Name, and IsFacility Level | ||
1263 | # and based on the IsF acility Le vel calls Add-Facili tyWorkflow or Add-Si teCollecti onWorkFlow | ||
1264 | if ($wfType -eq "Facil ityList") { | ||
1265 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1266 | Add-Faci lityWorkfl ow -featur eTemplateN ame "$($ne wWfName).w sp" -newFe atureId $n ewFeatureI d -searchD isplay $ne wWfName -o ldFeatureI d $oldFeat ureId -lis tName $tar getName -u nInstall $ False | ||
1267 | } elseif (($ wfType -eq "SiteList ") -or (($ wfType -eq "Site"))) { | ||
1268 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1269 | Add-Site Collection WorkFlow - featureTem plateName "$($newWfN ame).wsp" -newFeatur eId $newFe atureId -s earchDispl ay $newWfN ame -oldFe atureId $o ldFeatureI d -unInsta ll $False | ||
1270 | } elseif ($w fType -eq "SiteWFCon tentTypeAs sociation" ) { | ||
1271 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1272 | Add-Reus ableWorkFl owToConten tType -fea tureTempla teName "$( $newWfName ).wsp" -ne wFeatureId $newFeatu reId -sear chDisplay $newWfName -oldFeatu reId $oldF eatureId - contentTyp eName $tar getName -u nInstall $ False | ||
1273 | } elseif ($w fType -eq "SiteEvent Receiver") { | ||
1274 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1275 | Add-Even tReceiverT oContentTy pe -featur eTemplateN ame "$($ne wWfName).w sp" -newFe atureId $n ewFeatureI d -searchD isplay $ne wWfName -o ldFeatureI d $OldWFNa me -conten tTypeName $targetNam e -unInsta ll $False | ||
1276 | } else { | ||
1277 | write-lo g -message "ERROR: U nknown wfT ype: wfTyp e: $($wfTy pe)" -cons oleForegro und Red -L evel "ERRO R" | ||
1278 | } | ||
1279 | |||
1280 | #> | ||
1281 | |||
1282 | try { | ||
1283 | # GET THE SI TE | ||
1284 | $_ siteURL = Get-SiteUR L | ||
1285 | $w = Get-SPW eb $_siteU RL | ||
1286 | wr ite-log -m essage "$( [String]:: Format("Ad d-SiteColl ectionWork flow Proce sing web { 0}",$w.Url ))" -Conso leForegrou nd Yellow | ||
1287 | |||
1288 | #$ featureTem plateName= "Notificat ion Workfl ow Configu ration Wor kflow.wsp" | ||
1289 | #$ newFeature Id="df4391 92-e32f-47 60-9bef-d2 39d8519593 " | ||
1290 | |||
1291 | $t empFeature Id = $Null | ||
1292 | wr ite-log -m essage " T rying to f ind Featur e $searchD isplay whe n adding F eature $fe atureTempl ateName" - consoleFor eground Ye llow | ||
1293 | $O ldfeature = Get-SPFe ature -Lim it ALL -W eb $w.Url | Where-Ob ject {($_. DisplayNam e -like $s earchDispl ay) -or ($ _.DisplayN ame -like $featureTe mplateName )} | ||
1294 | |||
1295 | if ($Oldfeatu re -ne $Nu ll) { | ||
1296 | write-lo g -message "Found Ol d Feature $Oldfeatur e" -Consol eForegroun d Yellow | ||
1297 | $tempFea tureId = $ Oldfeature .Id | ||
1298 | } | ||
1299 | if ($tempFea tureId -eq $null) | ||
1300 | { | ||
1301 | $tempFea tureId = $ oldFeature Id | ||
1302 | } | ||
1303 | wr ite-log -m essage "Ca lling Depl oy-Feature on $w wit h $feature TemplateNa me OldFeat ureId $tem pFeatureId FeatureId $newFeatu reId " | ||
1304 | De ploy-Featu re -SiteCo llection $ _siteURL - site $w.Ur l -Feature Name $feat ureTemplat eName -Old FeatureId $tempFeatu reId -Feat ureId $new FeatureId -file $scr ipt -bolUn install $u nInstall - bolEnableF eatureOnly $False | ||
1305 | |||
1306 | } catc h { | ||
1307 | wr ite-log -m essage "$( [String]:: Format("Er ror proces sing web a t $_siteUR L, with Ex ception: { 0}", $_.Ex ception.Me ssage))" - ConsoleFor eground Re d | ||
1308 | if ($($_.Exc eption.Err orRecord)) { write-l og -messag e "$($_.Ex ception.Er rorRecord) " -console Foreground Red } | ||
1309 | if ($($_.Exc eption.sta cktrace)) { write-lo g -message "$($_.Exc eption.sta cktrace)" -consoleFo reground R ed } | ||
1310 | if ($($_.Scr iptStackTr ace)) { wr ite-log -m essage "$( $_.ScriptS tackTrace) " -console Foreground Red } | ||
1311 | } | ||
1312 | } | ||
1313 | |||
1314 | function A dd-Reusabl eWorkFlowT oContentTy pe ($featu reTemplate Name, $new FeatureId, $oldFeatu reId, $sea rchDisplay , $content TypeName, $unInstall ) { | ||
1315 | <# | ||
1316 | |||
1317 | .SYNOP SIS | ||
1318 | Ad ds a reusa ble workfl ow to a co ntent type at the si te collect ion level | ||
1319 | |||
1320 | .DESCR IPTION | ||
1321 | Ca lls Deploy Feature pa ssing the incoming p arameters then adds the workfl ow feature to the co ntent type . | ||
1322 | |||
1323 | .PARAM ETER featu reTemplate Name | ||
1324 | [S tring] The name of t he WSP wor kflow temp late file with the . wsp extens ion added. | ||
1325 | |||
1326 | .PARAM ETER newFe atureId | ||
1327 | [S tring] The featureID GUID from inside th e wsp file . | ||
1328 | |||
1329 | .PARAM ETER oldFe atureName | ||
1330 | [S tring] The name or O ld Feature Id (guid) of the wo rkflow tha t should b e deleted or replace d by the n ew Workflo w. | ||
1331 | |||
1332 | .PARAM ETER searc hDisplay | ||
1333 | [S tring] The name of t he WSP wor kflow temp late file without th e .wsp ext ension. | ||
1334 | |||
1335 | .PARAM ETER conte ntTypeName | ||
1336 | [S tring] The name of t he content type. | ||
1337 | |||
1338 | .PARAM ETER unIns tall | ||
1339 | [b oolean] In dicates if the workf low should be uninst alled. | ||
1340 | |||
1341 | .EXAMPL E | ||
1342 | # This examp le reads a list of w orkflows f rom WfList .csv file that conta in the New Workflow Name, New Feature Id , Old Work flow Name, the List Name, and IsFacility Level | ||
1343 | # and based on the IsF acility Le vel calls Add-Facili tyWorkflow or Add-Si teCollecti onWorkFlow | ||
1344 | if ($wfType -eq "Facil ityList") { | ||
1345 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1346 | Add-Faci lityWorkfl ow -featur eTemplateN ame "$($ne wWfName).w sp" -newFe atureId $n ewFeatureI d -searchD isplay $ne wWfName -o ldFeatureI d $oldFeat ureId -lis tName $tar getName -u nInstall $ False | ||
1347 | } elseif (($ wfType -eq "SiteList ") -or (($ wfType -eq "Site"))) { | ||
1348 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1349 | Add-Site Collection WorkFlow - featureTem plateName "$($newWfN ame).wsp" -newFeatur eId $newFe atureId -s earchDispl ay $newWfN ame -oldFe atureId $o ldFeatureI d -unInsta ll $False | ||
1350 | } elseif ($w fType -eq "SiteWFCon tentTypeAs sociation" ) { | ||
1351 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1352 | Add-Reus ableWorkFl owToConten tType -fea tureTempla teName "$( $newWfName ).wsp" -ne wFeatureId $newFeatu reId -sear chDisplay $newWfName -oldFeatu reId $oldF eatureId - contentTyp eName $tar getName -u nInstall $ False | ||
1353 | } elseif ($w fType -eq "SiteEvent Receiver") { | ||
1354 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1355 | Add-Even tReceiverT oContentTy pe -featur eTemplateN ame "$($ne wWfName).w sp" -newFe atureId $n ewFeatureI d -searchD isplay $ne wWfName -o ldFeatureI d $OldWFNa me -conten tTypeName $targetNam e -unInsta ll $False | ||
1356 | } else { | ||
1357 | write-lo g -message "ERROR: U nknown wfT ype: wfTyp e: $($wfTy pe)" -cons oleForegro und Red -L evel "ERRO R" | ||
1358 | } | ||
1359 | |||
1360 | #> | ||
1361 | |||
1362 | try { | ||
1363 | # GET THE SI TE | ||
1364 | $_ siteURL = Get-SiteUR L | ||
1365 | $w = Get-SPW eb $_siteU RL | ||
1366 | wr ite-log -m essage "$( [String]:: Format("Ad d-Reusable WorkFlowTo ContentTyp e Procesin g web {0}" ,$w.Url))" -ConsoleF oreground Yellow | ||
1367 | |||
1368 | $t empFeature Id = $Null | ||
1369 | wr ite-log -m essage " T rying to f ind Featur e $searchD isplay whe n adding F eature $fe atureTempl ateName" - consoleFor eground Ye llow | ||
1370 | $O ldfeature = Get-SPFe ature -Lim it ALL -W eb $w.Url | Where-Ob ject {($_. DisplayNam e -like $s earchDispl ay) -or ($ _.DisplayN ame -like $featureTe mplateName )} | ||
1371 | |||
1372 | if ($Oldfeatu re -ne $Nu ll) { | ||
1373 | write-lo g -message "Found Ol d Feature $Oldfeatur e" -Consol eForegroun d Yellow | ||
1374 | $tempFea tureId = $ Oldfeature .Id | ||
1375 | } | ||
1376 | if ($tempFea tureId -eq $null) | ||
1377 | { | ||
1378 | $tempFea tureId = $ oldFeature Id | ||
1379 | } | ||
1380 | wr ite-log -m essage "Ca lling Depl oy-FarmWFF eature on $w with $f eatureTemp lateName O ldFeatureI d $tempFea tureId Fea tureId $ne wFeatureId " | ||
1381 | De ploy-FarmW FFeature - SiteCollec tion $_sit eURL -site $w.Url -F eatureName $featureT emplateNam e -OldFeat ureId $tem pFeatureId -FeatureI d $newFeat ureId -fil e $Global: script -bo lUninstall $unInstal l -bolEnab leFeatureO nly $False | ||
1382 | } catc h { | ||
1383 | wr ite-log -m essage "$( [String]:: Format("Er ror proces sing web a t $_siteUR L, with Ex ception: { 0}", $_.Ex ception.Me ssage))" - ConsoleFor eground Re d | ||
1384 | if ($($_.Exc eption.Err orRecord)) { write-l og -messag e "$($_.Ex ception.Er rorRecord) " -console Foreground Red } | ||
1385 | if ($($_.Exc eption.sta cktrace)) { write-lo g -message "$($_.Exc eption.sta cktrace)" -consoleFo reground R ed } | ||
1386 | if ($($_.Scr iptStackTr ace)) { wr ite-log -m essage "$( $_.ScriptS tackTrace) " -console Foreground Red } | ||
1387 | } | ||
1388 | } | ||
1389 | |||
1390 | function A dd-EventRe ceiverToCo ntentType ($featureT emplateNam e, $newFea tureId, $o ldFeatureI d, $search Display, $ contentTyp eName, $un Install) { | ||
1391 | <# | ||
1392 | |||
1393 | .SYNOP SIS | ||
1394 | Ad ds a reusa ble workfl ow to a co ntent type at the si te collect ion level | ||
1395 | |||
1396 | .DESCR IPTION | ||
1397 | Ca lls Deploy Feature pa ssing the incoming p arameters then adds the workfl ow feature to the co ntent type . | ||
1398 | |||
1399 | .PARAM ETER featu reTemplate Name | ||
1400 | [S tring] The name of t he WSP wor kflow temp late file with the . wsp extens ion added. | ||
1401 | |||
1402 | .PARAM ETER newFe atureId | ||
1403 | [S tring] The featureID GUID from inside th e wsp file . | ||
1404 | |||
1405 | .PARAM ETER oldFe atureName | ||
1406 | [S tring] The name or O ld Feature Id (guid) of the wo rkflow tha t should b e deleted or replace d by the n ew Workflo w. | ||
1407 | |||
1408 | .PARAM ETER searc hDisplay | ||
1409 | [S tring] The name of t he WSP wor kflow temp late file without th e .wsp ext ension. | ||
1410 | |||
1411 | .PARAM ETER conte ntTypeName | ||
1412 | [S tring] The name of t he content type. | ||
1413 | |||
1414 | .PARAM ETER unIns tall | ||
1415 | [b oolean] In dicates if the workf low should be uninst alled. | ||
1416 | |||
1417 | .EXAMPL E | ||
1418 | # This examp le reads a list of w orkflows f rom WfList .csv file that conta in the New Workflow Name, New Feature Id , Old Work flow Name, the List Name, and IsFacility Level | ||
1419 | # and based on the IsF acility Le vel calls Add-Facili tyWorkflow or Add-Si teCollecti onWorkFlow | ||
1420 | if ($wfType -eq "Facil ityList") { | ||
1421 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1422 | Add-Faci lityWorkfl ow -featur eTemplateN ame "$($ne wWfName).w sp" -newFe atureId $n ewFeatureI d -searchD isplay $ne wWfName -o ldFeatureI d $oldFeat ureId -lis tName $tar getName -u nInstall $ False | ||
1423 | } elseif (($ wfType -eq "SiteList ") -or (($ wfType -eq "Site"))) { | ||
1424 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1425 | Add-Site Collection WorkFlow - featureTem plateName "$($newWfN ame).wsp" -newFeatur eId $newFe atureId -s earchDispl ay $newWfN ame -oldFe atureId $o ldFeatureI d -unInsta ll $False | ||
1426 | } elseif ($w fType -eq "SiteWFCon tentTypeAs sociation" ) { | ||
1427 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1428 | Add-Reus ableWorkFl owToConten tType -fea tureTempla teName "$( $newWfName ).wsp" -ne wFeatureId $newFeatu reId -sear chDisplay $newWfName -oldFeatu reId $oldF eatureId - contentTyp eName $tar getName -u nInstall $ False | ||
1429 | } elseif ($w fType -eq "SiteEvent Receiver") { | ||
1430 | $Global: script = J oin-Path $ fileLocati onTemplate "$($newWf Name).wsp" | ||
1431 | Add-Even tReceiverT oContentTy pe -featur eTemplateN ame "$($ne wWfName).w sp" -newFe atureId $n ewFeatureI d -searchD isplay $ne wWfName -o ldFeatureI d $OldWFNa me -conten tTypeName $targetNam e -unInsta ll $False | ||
1432 | } else { | ||
1433 | write-lo g -message "ERROR: U nknown wfT ype: wfTyp e: $($wfTy pe)" -cons oleForegro und Red -L evel "ERRO R" | ||
1434 | } | ||
1435 | |||
1436 | #> | ||
1437 | try { | ||
1438 | # GET THE SI TE | ||
1439 | $_ siteURL = Get-SiteUR L | ||
1440 | $w = Get-SPW eb $_siteU RL | ||
1441 | wr ite-log -m essage "$( [String]:: Format("Ad d-EventRec eiverToCon tentType P rocesing w eb {0}",$w .Url))" -C onsoleFore ground Yel low | ||
1442 | |||
1443 | $t empFeature Id = $Null | ||
1444 | wr ite-log -m essage " T rying to f ind Featur e $searchD isplay whe n adding F eature $fe atureTempl ateName" - consoleFor eground Ye llow | ||
1445 | $O ldfeature = Get-SPFe ature -Lim it ALL -W eb $w.Url | Where-Ob ject {($_. DisplayNam e -like $s earchDispl ay) -or ($ _.DisplayN ame -like $featureTe mplateName )} | ||
1446 | |||
1447 | if ($Oldfeatu re -ne $Nu ll) { | ||
1448 | write-lo g -message "Found Ol d Feature $Oldfeatur e" -Consol eForegroun d Yellow | ||
1449 | $tempFea tureId = $ Oldfeature .Id | ||
1450 | } | ||
1451 | if ($tempFea tureId -eq $null) | ||
1452 | { | ||
1453 | $tempFea tureId = $ oldFeature Id | ||
1454 | } | ||
1455 | wr ite-log -m essage "Ca lling Depl oy-FarmERF eature on $w with $f eatureTemp lateName O ldFeatureI d $tempFea tureId Fea tureId $ne wFeatureId " | ||
1456 | De ploy-FarmE RFeature - SiteCollec tion $_sit eURL -site $w.Url -F eatureName $featureT emplateNam e -OldFeat ureId $tem pFeatureId -FeatureI d $newFeat ureId -fil e $Global: script -bo lUninstall $unInstal l -bolEnab leFeatureO nly $False | ||
1457 | } catc h { | ||
1458 | wr ite-log -m essage "$( [String]:: Format("Er ror proces sing web a t $_siteUR L, with Ex ception: { 0}", $_.Ex ception.Me ssage))" - ConsoleFor eground Re d | ||
1459 | if ($($_.Exc eption.Err orRecord)) { write-l og -messag e "$($_.Ex ception.Er rorRecord) " -console Foreground Red } | ||
1460 | if ($($_.Exc eption.sta cktrace)) { write-lo g -message "$($_.Exc eption.sta cktrace)" -consoleFo reground R ed } | ||
1461 | if ($($_.Scr iptStackTr ace)) { wr ite-log -m essage "$( $_.ScriptS tackTrace) " -console Foreground Red } | ||
1462 | } | ||
1463 | } | ||
1464 | |||
1465 | #region ut ility func tions Get- DateFromDa ys, Format -ListOutpu t, Get-Lis tInternalN ame | ||
1466 | function G et-DateFro mDays ($mi nusdays) { | ||
1467 | <# | ||
1468 | |||
1469 | .SYNOP SIS | ||
1470 | Ad ds the num ber of day s paramete r to today | ||
1471 | |||
1472 | .DESCR IPTION | ||
1473 | Ad ds the num ber of day s paramete r to today and retur ns the res ult. If mi nusdays is negative the result will be b efore toda y. | ||
1474 | |||
1475 | .PARAM ETER minus days | ||
1476 | [i nteger] th e number o f days to add to tod ay's date. to subtra ct days, p ass a nega tive numbe r | ||
1477 | |||
1478 | .NOTES | ||
1479 | No t used in RAMS-2.3.0 | ||
1480 | |||
1481 | .EXAMP LE | ||
1482 | $t argetDate = Get-Date FromDays - 10 | ||
1483 | |||
1484 | #> | ||
1485 | |||
1486 | $days = $minusda ys | ||
1487 | $count = $collLi stItems.Co unt; | ||
1488 | $date = get-date ; | ||
1489 | return $date.Add Days($days ); | ||
1490 | |||
1491 | } | ||
1492 | |||
1493 | function F ormat-List Output($li stTable) { | ||
1494 | <# | ||
1495 | |||
1496 | .SYNOP SIS | ||
1497 | Fo rmat a lis t output a s a list. | ||
1498 | |||
1499 | .DESCR IPTION | ||
1500 | wr apper func tion to fo romat a li st to the console as a list. | ||
1501 | |||
1502 | .PARAM ETER listT able | ||
1503 | [O bject] a l ist object that repr esents a S harePoint List | ||
1504 | |||
1505 | .NOTES | ||
1506 | No t used in RAMS-2.3.0 | ||
1507 | |||
1508 | .EXAMP LE | ||
1509 | $f acilityLis tItems = ( (Get-SiteW eb).Lists. TryGetList ("Faciliti es")).Item s | ||
1510 | Fo rmat-ListO utput $fac ilityListI tems | ||
1511 | |||
1512 | #> | ||
1513 | |||
1514 | $listTab le | Forma t-List | ||
1515 | } | ||
1516 | |||
1517 | function G et-ListInt ernalName ($staticNa me, $list) { | ||
1518 | <# | ||
1519 | |||
1520 | .SYNOP SIS | ||
1521 | Re turn the I nternal Na me of a co lumn on a list. | ||
1522 | |||
1523 | .DESCR IPTION | ||
1524 | Fo r the requ est static name and l ist, looku p and retu rn the int ernal name . | ||
1525 | |||
1526 | .PARAM ETER stati cName | ||
1527 | [s tring] the static na me of a si te column on a list | ||
1528 | |||
1529 | .PARAM ETER list | ||
1530 | [o bject] a l ist object that repr esents a S harePoint List | ||
1531 | |||
1532 | .NOTES | ||
1533 | No t used in RAMS-2.3.0 | ||
1534 | |||
1535 | .EXAMP LE | ||
1536 | $f acilitiesL ist = ((Ge t-SiteWeb) .Lists.Try GetList("F acilities" )) | ||
1537 | $l ocationSta ticName = "Location" | ||
1538 | $l ocationInt ernalName = Get-List InternalNa me $locati onStaticNa me $facili tiesList | ||
1539 | |||
1540 | #> | ||
1541 | |||
1542 | $list. Fields.Try GetFieldBy StaticName ($staticNa me).Intern alName | ||
1543 | return ; | ||
1544 | } | ||
1545 | |||
1546 | function G et-SPList( $web, $Nam e, $Url, $ subWeb) { | ||
1547 | <# | ||
1548 | |||
1549 | .SYNOP SIS | ||
1550 | Re turn the r equested l ist. | ||
1551 | |||
1552 | .DESCR IPTION | ||
1553 | At tempts to return the requested list by U RL and if that fails , tries by name. Ret urns null list if no thing is f ound. | ||
1554 | |||
1555 | .PARAM ETER web | ||
1556 | [M icrosoft.S harePoint. SPSecurabl eObject] a web objec t that rep resents th e site col lection. | ||
1557 | |||
1558 | .PARAM ETER Name | ||
1559 | [s tring] a l ist object that repr esents a S harePoint List | ||
1560 | |||
1561 | .PARAM ETER Url | ||
1562 | [s tring] The URL of th e list. | ||
1563 | |||
1564 | .PARAM ETER subWe b | ||
1565 | [M icrosoft.S harePoint. SPSecurabl eObject] a web objec t that rep resents th e subsite spweb. | ||
1566 | |||
1567 | .EXAMP LE | ||
1568 | $f acilityLis t = Get-SP List -web $webSite - Name "Faci lity" -Url ($webSite .ServerRel ativeUrl + "/Lists/F acility/Al lItems.asp x") | ||
1569 | |||
1570 | .EXAMP LE | ||
1571 | $l ist = Get- SPList -we b $Site -N ame $listN ame -Url $ listUrl -s ubWeb $sub Site | ||
1572 | #> | ||
1573 | |||
1574 | $list = $null | ||
1575 | try { | ||
1576 | if ($subWeb - eq $null) { | ||
1577 | $list = $web.GetLi stFromURL( $Url) | ||
1578 | } else { | ||
1579 | $list = $subWeb.Ge tListFromU RL($Url) | ||
1580 | } | ||
1581 | r eturn $lis t | ||
1582 | } catc h { | ||
1583 | tr y { | ||
1584 | if($subW eb -eq $nu ll) { | ||
1585 | $lis t = $web.G etList($Na me) | ||
1586 | } else { | ||
1587 | $lis t = $subWe b.GetList( $Name) | ||
1588 | } | ||
1589 | return $list | ||
1590 | } catch { | ||
1591 | return $ list | ||
1592 | } | ||
1593 | } | ||
1594 | } | ||
1595 | |||
1596 | function R emove-Data FromAList ($Site, $s ubSite, $f ilterDate, $listUrl, $listName ) { | ||
1597 | <# | ||
1598 | |||
1599 | .SYNOP SIS | ||
1600 | De letes Data from the specified list creat ed before the filter Date. | ||
1601 | |||
1602 | .DESCR IPTION | ||
1603 | Re moves data from the specified list where the creat ed date oc curs befor e the filt erDate. | ||
1604 | |||
1605 | .PARAM ETER Site | ||
1606 | [M icrosoft.S harePoint. SPSecurabl eObject] a web objec t that rep resents th e site col lection. | ||
1607 | |||
1608 | .PARAM ETER subSi te | ||
1609 | [M icrosoft.S harePoint. SPSecurabl eObject] O ptional a web object that repr esents the subsite s pweb. | ||
1610 | |||
1611 | .PARAM ETER filte rDate | ||
1612 | [d ate] The d ate consid ered when determinin g to delet e the reco rds. | ||
1613 | |||
1614 | .PARAM ETER listU rl | ||
1615 | [s tring] The URL of th e list to delete the data from . | ||
1616 | |||
1617 | .PARAM ETER listN ame | ||
1618 | [s tring] The name of t he list. | ||
1619 | |||
1620 | .EXAMP LE | ||
1621 | #g et site co llection | ||
1622 | $s ite= Get-S iteURL | ||
1623 | $x = $site.T oString(); | ||
1624 | $u rl = $x.Su bstring($x .IndexOf(" =")+1) | ||
1625 | $w = Get-Sit eWeb | ||
1626 | |||
1627 | #f ilter by d ays | ||
1628 | $f ilterPrior Date = $cl eanDate | ||
1629 | |||
1630 | #D elete Appl ication li st for old er studies . | ||
1631 | $l istUrl = $ url + "/Li sts/Applic ation/AllI tems.aspx" | ||
1632 | $l istOfStudi es = Get-C olumnValue FromAList -Site $w - filterDate $filterPr iorDate -l istUrl $li stUrl -lis tColumnNam e "Study_I D" | ||
1633 | |||
1634 | Re move-DataF romAList - Site $w -f ilterDate $filterPri orDate -li stUrl $lis tUrl | ||
1635 | |||
1636 | #> | ||
1637 | |||
1638 | #get a collectio n of ids | ||
1639 | $items ToDelete = New-Objec t System.C ollections .ArrayList | ||
1640 | $list = Get-SPLi st -web $S ite -Name $listName -Url $list Url -subWe b $subSite | ||
1641 | #get a pplication list | ||
1642 | if($li st -ne $nu ll) { | ||
1643 | #G et all ite ms in this list and save them to a varia ble | ||
1644 | $i tems = $li st.items | ||
1645 | $l istTitle = $list.Tit le | ||
1646 | $i temCount = 0 | ||
1647 | #G o through all items | ||
1648 | wr ite-log -m essage "To tal Items in the $($ list.Entit yTypeName) : $($item s.Count)" -ConsoleFo reground G reen | ||
1649 | fo reach($ite m in $item s) | ||
1650 | { | ||
1651 | if($item ["Created" ] -lt $fil terDate) | ||
1652 | { | ||
1653 | if ( $item.Titl e -ne $nul l) { | ||
1654 | $itemDescr iption = $ item.Title | ||
1655 | } el seif ($ite m.Name -ne $null ) { | ||
1656 | $itemDescr iption = $ item.Name | ||
1657 | } el se { | ||
1658 | $itemDescr iption = " Unknown Ti tle or Nam e" | ||
1659 | } | ||
1660 | #add each item id to the delete li st | ||
1661 | writ e-log -mes sage "$ite mCount. Ad d item $($ item.ID) f rom the li st $($list Title) for Study: $( $item["Tit le"]) on $ ($item["Cr eated"])" -ConsoleFo reground C yan | ||
1662 | $ite msToDelete .Add($item .ID) | ||
1663 | $ite mCount ++; | ||
1664 | } | ||
1665 | } | ||
1666 | #n ow start d eleting th ose items | ||
1667 | if ($itemCoun t -eq 0) { | ||
1668 | write-lo g -message "Nothing to delete, count: $i temCount" -ConsoleFo reground Y ellow | ||
1669 | r eturn | ||
1670 | } | ||
1671 | wr ite-log -m essage "To tal items to be dele ted $itemC ount" -Con soleForegr ound Yello w | ||
1672 | fo reach($ite mToDelete in $itemsT oDelete) { | ||
1673 | write-lo g -message "Deleting item.Id $ itemToDele te with Ti tle $($ite m.Title) f rom $listT itle" -Con soleForegr ound Cyan | ||
1674 | $items.D eleteItemB yId($itemT oDelete); | ||
1675 | } | ||
1676 | $i tems.Updat e(); | ||
1677 | $l ist.Update (); | ||
1678 | wr ite-log -m essage "To tal Items After $($l ist.items. Count)" -C onsoleFore ground Gre en | ||
1679 | } else { | ||
1680 | wr ite-log -m essage No list found by the na me: $listU rl | ||
1681 | } | ||
1682 | } | ||
1683 | #endregion | ||
1684 | |||
1685 | #region fu nction Upd ate-UtilMF | ||
1686 | function U pdate-Util MF { | ||
1687 | <# | ||
1688 | |||
1689 | .SYNOP SIS | ||
1690 | Up date this module's m anifest. | ||
1691 | |||
1692 | .DESCR IPTION | ||
1693 | Ge nerate the manifest for this m odule. | ||
1694 | |||
1695 | .NOTES | ||
1696 | No t used in RAMS-2.3.0 | ||
1697 | |||
1698 | .EXAMP LE | ||
1699 | Up date-UtilM F | ||
1700 | |||
1701 | #> | ||
1702 | New-Module Manifest - Path .\RAM S_Module_U til.psd1 - ModuleVers ion 1.0.0 -Author "C hita Nilak , ByLight" -RootModu le .\RAMS_ Module_Uti l.psm1 -De scription "RAMS Util ity Functi ons" -Comp anyName " DN S" -Verbos e | ||
1703 | } | ||
1704 | #endregion | ||
1705 | |||
1706 | function G et-RAMSEnv ($host) { | ||
1707 | <# | ||
1708 | |||
1709 | .SYNOP SIS | ||
1710 | Re trieve the environme nt informa tion from the Env.js on file | ||
1711 | |||
1712 | .DESCR IPTION | ||
1713 | Re ad the Env .json file and retur n the info rmation fo r the spec ified host . Reads th e Env.host from the current di rectory an d searches for the e nvironment informati on for the given hos t. | ||
1714 | |||
1715 | .PARAM ETER host | ||
1716 | [S tring] The name of t he compute r to looku p in the e nv.host fi le | ||
1717 | |||
1718 | .EXAMP LE | ||
1719 | $G lobal:host Info = Get -RAMSEnv - host $env: COMPUTERNA ME | ||
1720 | |||
1721 | #> | ||
1722 | |||
1723 | $_host = $host | ||
1724 | $_env = Get-Cont ent .\Env. json | Con vertFrom-J son | ||
1725 | $_serv er = $null | ||
1726 | switch ($_host) { | ||
1727 | $_ env.DEV.sp {$_server = $_env.D EV} | ||
1728 | $_ env.TEST.s p {$_serve r = $_env. TEST} | ||
1729 | $_ env.PPD.sp {$_server = $_env.P PD} | ||
1730 | $_ env.SQA.sp {$_server = $_env.S QA} | ||
1731 | $_ env.PROD.s p {$_serve r = $_env. PROD} | ||
1732 | } | ||
1733 | return $_server | ||
1734 | } | ||
1735 | |||
1736 | function G et-RAMSEnv Name ($hos t) { | ||
1737 | <# | ||
1738 | |||
1739 | .SYNOP SIS | ||
1740 | Re trieve the environme nt informa tion from the Env.js on file | ||
1741 | |||
1742 | .DESCR IPTION | ||
1743 | Re ad the Env .json file and retur n the info rmation fo r the spec ified host . Reads th e Env.host from the current di rectory an d searches for the e nvironment informati on for the given hos t. | ||
1744 | |||
1745 | .PARAM ETER host | ||
1746 | [S tring] The name of t he compute r to looku p in the e nv.host fi le | ||
1747 | |||
1748 | .EXAMP LE | ||
1749 | $e nvName = G et-RAMSEnv Name -host ($env:COM PUTERNAME) | ||
1750 | |||
1751 | #> | ||
1752 | |||
1753 | $_host = $host | ||
1754 | $_env = Get-Cont ent .\Env. json | Con vertFrom-J son | ||
1755 | $_serv er = $null | ||
1756 | switch ($_host) { | ||
1757 | $_ env.DEV.sp {$_server = 'DEV'} | ||
1758 | $_ env.TEST.s p {$_serve r = 'TEST' } | ||
1759 | $_ env.PPD.sp {$_server = 'PPD'} | ||
1760 | $_ env.SQA.sp {$_server = 'SQA'} | ||
1761 | $_ env.PROD.s p {$_serve r = 'PROD' } | ||
1762 | } | ||
1763 | return $_server | ||
1764 | } | ||
1765 | |||
1766 | function N ew-RAMSEnv { | ||
1767 | <# | ||
1768 | |||
1769 | .SYNOP SIS | ||
1770 | Cr eates a ne w, empty E nv.json fi le. | ||
1771 | |||
1772 | .DESCR IPTION | ||
1773 | Cr eates a ne w, empty E nv.json fi le with en tries for each envir onment and saves the results i n the curr ent direct ory. | ||
1774 | |||
1775 | .EXAMP LE | ||
1776 | Ne w-RAMSEnv | ||
1777 | |||
1778 | #> | ||
1779 | |||
1780 | $_serv erEnv = @{ | ||
1781 | DE V = @{ | ||
1782 | "sp" = " DNS "; | ||
1783 | "sql" = " DN S
|
||
1784 | "ssrs" = " DN S
|
||
1785 | "ssis" = " DN S
|
||
1786 | "s uperReader " = @(""," "); #READ- ONLY acces s to RAMS- DB | ||
1787 | "f armUser" = @("",""); #SharePoi nt Farm Ac count w/ l ocal Admin permissio n | ||
1788 | }; #DE V | ||
1789 | TE ST = @{ | ||
1790 | "sp" = " DNS "; | ||
1791 | "sql" = " DN S
|
||
1792 | "ssrs" = " DN S
|
||
1793 | "ssis" = " DN S
|
||
1794 | "s uperReader " = @(""," "); #READ- ONLY acces s to RAMS- DB | ||
1795 | "f armUser" = @("",""); #SharePoi nt Farm Ac count w/ l ocal Admin permissio n | ||
1796 | }; #TE ST | ||
1797 | SQ A = @{ | ||
1798 | "sp" = " DNS "; | ||
1799 | "sql" = " DNS "; | ||
1800 | "ssrs" = " DNS "; | ||
1801 | "ssis" = " DNS "; | ||
1802 | "s uperReader " = @(""," "); #READ- ONLY acces s to RAMS- DB | ||
1803 | "f armUser" = @("",""); #SharePoi nt Farm Ac count w/ l ocal Admin permissio n | ||
1804 | }; #SQA DNS"; | ||
1805 | "sql" = "D NS"; | ||
1806 | "ssrs" = " DNS "; | ||
1807 | "ssis" = " v DNS "; | ||
1808 | "s uperReader " = @(""," "); #READ- ONLY acces s to RAMS- DB | ||
1809 | "f armUser" = @("",""); #SharePoi nt Farm Ac count w/ l ocal Admin permissio n | ||
1810 | }; #PP D | ||
1811 | PR OD = @{ | ||
1812 | "sp" = " DNS "; | ||
1813 | "sql" = " DNS "; | ||
1814 | "ssrs" = " DNS "; | ||
1815 | "ssis" = " DNS "; | ||
1816 | "s uperReader " = @(""," "); #READ- ONLY acces s to RAMS- DB | ||
1817 | "f armUser" = @("",""); #SharePoi nt Farm Ac count w/ l ocal Admin permissio n | ||
1818 | }; #PR OD | ||
1819 | } | ||
1820 | if((Ge t-ChildIte m ".\" -Fi lter "ENV. json") -ne $null) { | ||
1821 | Re move-Item .\ENV.json -Verbose | ||
1822 | } | ||
1823 | Conver tTo-json $ _serverEnv -Compress | New-Ite m -Name EN V.json -Pa th .\ -Ite mType file -Force | ||
1824 | return Get-Conte nt .\Env.j son | Conv ertFrom-Js on | ||
1825 | } | ||
1826 | |||
1827 | function G et-Facilit ySites { | ||
1828 | <# | ||
1829 | |||
1830 | .SYNOP SIS | ||
1831 | Re turn the l ist of Sub site names . | ||
1832 | |||
1833 | .DESCR IPTION | ||
1834 | Lo op through the subsi tes and re turn an ar raylist of the subsi te names. | ||
1835 | |||
1836 | .NOTES | ||
1837 | No t used in RAMS-2.3.0 | ||
1838 | |||
1839 | .EXAMP LE | ||
1840 | Ge t-Facility Sites | ||
1841 | |||
1842 | #> | ||
1843 | |||
1844 | $webs = Get-Site Web | ||
1845 | $_faci lities = N ew-Object System.Col lections.A rrayList | ||
1846 | foreac h($web in $webs.Webs ) { | ||
1847 | $_f acilities. Add($web.N ame) | ||
1848 | } | ||
1849 | #retur n | ||
1850 | $_faci lities | ||
1851 | } | ||
1852 | |||
1853 | function N ew-RAMSGro up ($facil ity, $newG roupName, $newGroupP ermission, $groupOwn erSuffix, $newGroupD escSuffix) { | ||
1854 | <# | ||
1855 | |||
1856 | .SYNOP SIS | ||
1857 | Cr eates a ne w security group for a given f acility. | ||
1858 | |||
1859 | .DESCR IPTION | ||
1860 | Bu ilds a new facility security g roup with the provid ed permiss ions. If i t already exists, it is remove d and adde d again. | ||
1861 | |||
1862 | .PARAM ETER facil ity | ||
1863 | [s tring] the name of t he facilit y as it ex ists on th e Facility list. In the case o f Miami An imal Facil ity Manage rs, the fa cility is the Miami part. | ||
1864 | |||
1865 | .PARAM ETER newGr oupName | ||
1866 | [S tring] The name of t he securit y group. I n the case of Miami Animal Fac ility Mana gers, the newGroupNa me is the Animal Fac ility Mana gers part. | ||
1867 | |||
1868 | .PARAM ETER newGr oupPermiss ion | ||
1869 | [S tring] The standard SharePoint role to b e given to the secur ity group. | ||
1870 | |||
1871 | .PARAM ETER group OwnerSuffi x | ||
1872 | [S tring] The name of t he group o wner. Typi call "Loca l Site Adm inistrator s". The sc ript will prepend th e facility to the su ffix. | ||
1873 | |||
1874 | .PARAM ETER newGr oupDescSuf fix | ||
1875 | [S tring] The security group desc ription. I nformation al only. | ||
1876 | |||
1877 | .EXAMP LE | ||
1878 | Ne w-RAMSGrou p -facilit y $_.Title -newGroup Name "Anim al Facilit y Managers " -newGrou pPermissio n "Edit" - groupOwner Suffix "Lo cal Site A dministrat ors" -newG roupDescSu ffix "Anim al Facilit y Managers " | ||
1879 | |||
1880 | #> | ||
1881 | |||
1882 | #Get s ite and Gr oup object s | ||
1883 | $_url = Get-Site URL | ||
1884 | $_Site = Get-SPS ite -Ident ity $_url | ||
1885 | |||
1886 | #add n ew securit y group | ||
1887 | $_site Groups = $ _Site.Root Web.SiteGr oups | ||
1888 | $_owne rGroup = $ _siteGroup s["$facili ty $groupO wnerSuffix "] | ||
1889 | |||
1890 | #check if the gr oup alread y exist | ||
1891 | try { | ||
1892 | $_ siteGroups .Add("$fac ility $new GroupName" ,$_ownerGr oup,$null, "$facility $newGroup DescSuffix ") | ||
1893 | } | ||
1894 | catch { | ||
1895 | $_ siteGroups .Remove("$ facility $ newGroupNa me") | ||
1896 | $_ siteGroups .Add("$fac ility $new GroupName" ,$_ownerGr oup,$null, "$facility $newGroup DescSuffix ") | ||
1897 | } | ||
1898 | $_Site .RootWeb.U pdate() | ||
1899 | |||
1900 | #Chang e AO group permissio n at site collection level to EDIT | ||
1901 | $role = $_Site.R ootWeb.Rol eDefinitio ns[$newGro upPermissi on] | ||
1902 | $_newG roup = $_S ite.RootWe b.SiteGrou ps["$facil ity $newGr oupName"] | ||
1903 | $RoleA ssignment = New-Obje ct Microso ft.SharePo int.SPRole Assignment ($_newGrou p) | ||
1904 | $RoleA ssignment. RoleDefini tionBindin gs.Add($ro le) | ||
1905 | |||
1906 | # the following could be f or a web, list or it em object | ||
1907 | $_Site .RootWeb.R oleAssignm ents.Add($ RoleAssign ment) | ||
1908 | $_Site .RootWeb.U pdate() | ||
1909 | write- log -messa ge "$facil ity $newGr oupName ha s been add ed w/ $new GroupPermi ssion perm ission on $_Site" -c onsoleFore ground yel low | ||
1910 | |||
1911 | #dispo se site ob ject | ||
1912 | $_Site .Dispose() ; | ||
1913 | } | ||
1914 | |||
1915 | function A dd-Facilit yGroup ($n ewGroupNam e, $newGro upPermissi on) { | ||
1916 | <# | ||
1917 | |||
1918 | .SYNOP SIS | ||
1919 | Gr ants the p ermission to the fac ility subs ite. | ||
1920 | |||
1921 | .DESCR IPTION | ||
1922 | Fo r each fac ility in t he Facilit y List, lo op through each gran ting the n ewGroupNam e the newG roupPermis sion. | ||
1923 | |||
1924 | .PARAM ETER newGr oupName | ||
1925 | [S tring] The name of t he securit y group. I n the case of Miami Animal Fac ility Mana gers, the newGroupNa me is the Animal Fac ility Mana gers part. | ||
1926 | |||
1927 | .PARAM ETER newGr oupPermiss ion | ||
1928 | [S tring] The standard SharePoint role to b e given to the secur ity group. | ||
1929 | |||
1930 | .EXAMP LE | ||
1931 | Ad d-Facility Group -new GroupName "Animal Fa cility Man agers" -ne wGroupPerm ission "Ed it" | ||
1932 | |||
1933 | #> | ||
1934 | |||
1935 | $_faci lityWebs = Get-SiteW eb | ||
1936 | $_faci lityList = $_facilit yWebs.GetL istFromUrl ("Lists/Fa cility/All Items.aspx ") | ||
1937 | |||
1938 | #add e ach new gr oups to th e respecti ve facilit y sub-site . | ||
1939 | foreac h ($item i n $_facili tyList.Ite ms) { | ||
1940 | #f acility su b-site | ||
1941 | $f acilitySub site = $it em["Facili ty Subsite "] | ||
1942 | #f acility na me | ||
1943 | $f acilityNam e = $item[ "Facility Name"] | ||
1944 | #f oreach | ||
1945 | fo reach ($fa cilityWeb in $_facil ityWebs.We bs) { | ||
1946 | if($faci litySubsit e.IndexOf( $facilityW eb.Name) - gt 0) { | ||
1947 | #get role | ||
1948 | $rol e = $facil ityWeb.Rol eDefinitio ns[$newGro upPermissi on] | ||
1949 | $_ne wGroup = $ _facilityW ebs.SiteGr oups["$fac ilityName $newGroupN ame"] | ||
1950 | $Rol eAssignmen t = New-Ob ject Micro soft.Share Point.SPRo leAssignme nt($_newGr oup) | ||
1951 | $Rol eAssignmen t.RoleDefi nitionBind ings.Add($ role) | ||
1952 | |||
1953 | # th e followin g could be for a web , list or item objec t | ||
1954 | $fac ilityWeb.R oleAssignm ents.Add($ RoleAssign ment) | ||
1955 | $fac ilityWeb.U pdate() | ||
1956 | writ e-log -mes sage "$_ne wGroup has been adde d w/ $newG roupPermis sion permi ssion on $ facilityWe b" -consol eForegroun d yellow | ||
1957 | |||
1958 | #$it em["Resear ch Complia nce Office rs"] | ||
1959 | } | ||
1960 | $facilit yWeb.Updat e() | ||
1961 | } | ||
1962 | } | ||
1963 | } | ||
1964 | |||
1965 | function R emove-Work Flow { | ||
1966 | <# | ||
1967 | |||
1968 | .SYNOP SIS | ||
1969 | Re moves the requested workflow f rom the si te collect ion and th e feature from the F arm | ||
1970 | |||
1971 | .DESCR IPTION | ||
1972 | Re moves the workflow f rom the si te collect ion and th e feature from the f arm. Start s by disab ling the S PFeature, then Unins talls the | ||
1973 | SP UserSoluti on, then R emoves the SPUserSol ution. Nex t, it loop s through the defini tions and subscripti ons, delet ing them a ll. | ||
1974 | |||
1975 | .PARAM ETER wfMat chName | ||
1976 | [S tring] The name of t he workflo w. | ||
1977 | |||
1978 | .PARAM ETER wfWeb | ||
1979 | [M icrosoft.S harePoint. SPWeb] The SPWeb of the site c ollection or facilit y subsite. | ||
1980 | |||
1981 | .PARAM ETER SiteC ollection | ||
1982 | [S tring] The URL of th e site col lection. | ||
1983 | |||
1984 | .NOTES | ||
1985 | No t used in RAMS-2.3.0 | ||
1986 | Do es not wor k because it may not completel y remove t he workflo w. | ||
1987 | |||
1988 | .EXAMP LE | ||
1989 | Re move-WorkF low -wfMat chName ($F eatureName .Replace(" .wsp","")) -wfWeb $w eb -SiteCo llection ( Get-SiteUR L) | ||
1990 | |||
1991 | #> | ||
1992 | |||
1993 | Param( | ||
1994 | [P arameter(M andatory=$ True)] | ||
1995 | [s tring]$wfM atchName, | ||
1996 | |||
1997 | [P arameter(M andatory=$ True)] | ||
1998 | [M icrosoft.S harePoint. SPWeb]$wfW eb, | ||
1999 | |||
2000 | [P arameter(M andatory=$ True)] | ||
2001 | [s tring]$Sit eCollectio n | ||
2002 | |||
2003 | ) | ||
2004 | $SiteC ollectionw eb = Get-S PWeb $Site Collection | ||
2005 | $wfm = New-Objec t Microsof t.SharePoi nt.Workflo wServices. WorkflowSe rvicesMana ger($wfWeb ); | ||
2006 | $wfss =$wfm.GetW orkflowSub scriptionS ervice() | ||
2007 | $wfds = $wfm.Get WorkflowDe ploymentSe rvice() | ||
2008 | $wfis= $wfm.GetWo rkflowInst anceServic e() | ||
2009 | #$wfss .Enumerate Subscripti ons() | ||
2010 | |||
2011 | write- log -messa ge "Remove -WorkFlow Feature: $ wfMatchNam e on site: $($wfWeb. Url)" -Con soleForegr ound Yello w | ||
2012 | write- log -messa ge " Disa ble-SPFeat ure $wfMat chName" -C onsoleFore ground Gra y | ||
2013 | #Disab le-SPFeatu re -Identi ty $wfMatc hName -Url $SiteColl ectionweb. Url -Confi rm:$false -Force -Er rorAction SilentlyCo ntinue | ||
2014 | Disabl e-SPFeatur e -Identit y $wfMatch Name -Url $SiteColle ctionweb.U rl -Confir m:$false - Force | ||
2015 | $check SPFeature = Get-SPFe ature -Ide ntity $wfM atchName - Site $Site Collection web.Url | ||
2016 | if($ch eckSPFeatu re -ne $nu ll){ | ||
2017 | wr ite-log -m essage " The feat ure: $wfMa tchName is not disab led" -cons oleForegro und Red | ||
2018 | } else { | ||
2019 | wr ite-log -m essage " The feat ure: $wfMa tchName is not found " -console Foreground Green | ||
2020 | } | ||
2021 | |||
2022 | write- log -messa ge " Unin stall-SPUs erSolution $wfMatchN ame" -Cons oleForegro und Gray | ||
2023 | Uninst all-SPUser Solution - Identity $ wfMatchNam e -Site $S iteCollect ionweb.Sit e | ||
2024 | $check SPUserSolu tion = Get -SPUserSol ution -Ide ntity $wfM atchName - Site $Site Collection web.Url | ||
2025 | if($ch eckSPUserS olution -n e $null){ | ||
2026 | wr ite-log -m essage " The SPUs erSolution : $wfMatch Name is no t disabled " -console Foreground Red | ||
2027 | } else { | ||
2028 | wr ite-log -m essage " The SPUs erSolution : $wfMatch Name is no t found" - consoleFor eground Gr een | ||
2029 | } | ||
2030 | |||
2031 | write- log -messa ge " Remo ve-SPUserS olution $w fMatchName " -Console Foreground Gray | ||
2032 | Remove -SPUserSol ution -Ide ntity $wfM atchName - Site $Site Collection web.Site | ||
2033 | |||
2034 | foreac h($wf in $ wfds.Enume rateDefini tions($fal se)){ | ||
2035 | if ($wf.prope rties['Def inition.Di splayName' ] -match $ wfMatchNam e){ | ||
2036 | $wfDefId = $wf.pro perties['D efinition. Id'] | ||
2037 | $wfSubId = $wf.pro perties['S ubscriptio nId'] | ||
2038 | write-lo g -message "$($wf.pr operties[' Definition .DisplayNa me']) wfDe ployment D eleted fro m web $($w fWeb)" -co nsoleForeg round Gray | ||
2039 | $wfss.De leteDefini tion($wfDe fId) | ||
2040 | write-lo g -message " - Succe ss" -Conso leForegrou nd Green | ||
2041 | $wfSub = $wfss.Get Subscripti on( $wfSub Id) | ||
2042 | write-lo g -message "$($wf.pr operties[' Definition .DisplayNa me']) wfSu bscription Deleted f rom web $( $wfWeb)" - consoleFor eground Gr ay | ||
2043 | if($wfSu b -ne $nul l) { | ||
2044 | $wfd s.DeleteSu bscription ($wfSubId) | ||
2045 | writ e-log -mes sage " - S uccess" -C onsoleFore ground Gre en | ||
2046 | } else { | ||
2047 | writ e-log -mes sage " - N OT FOUND" -ConsoleFo reground R ED | ||
2048 | } | ||
2049 | } | ||
2050 | } | ||
2051 | |||
2052 | #$wfDe fs = $wfds .Enumerate Definition s($false) | ||
2053 | #forea ch ($wfDef in $wfDef s){ | ||
2054 | # i f($wfDef.N ame -match $wfMatchN ame){ | ||
2055 | # $wfds.D eleteDefin ition($wfD ef.Id) | ||
2056 | # } | ||
2057 | #} | ||
2058 | #$wfWe b.Update() | ||
2059 | |||
2060 | |||
2061 | # TAR Adding co mplete rem oval of Wo rkflow | ||
2062 | $wfWeb .Update() | ||
2063 | |||
2064 | } | ||
2065 | |||
2066 | function R ename-List ($spWeb,$l istName,$n ewTitle) { | ||
2067 | <# | ||
2068 | |||
2069 | .SYNOP SIS | ||
2070 | Re names a li st to a ne w name and location. | ||
2071 | |||
2072 | .DESCR IPTION | ||
2073 | Re names a li st by movi ng it to a new name and locati on. | ||
2074 | |||
2075 | .PARAM ETER spWeb | ||
2076 | [M icrosoft.S harePoint. SPWeb] The SPWeb of the site c ollection or facilit y subsite. | ||
2077 | |||
2078 | .PARAM ETER listN ame | ||
2079 | [S tring] The original name of th e list. | ||
2080 | |||
2081 | .PARAM ETER newTi tle | ||
2082 | [S tring] The new name of the lis t. | ||
2083 | |||
2084 | .NOTES | ||
2085 | No t used in RAMS-2.3.0 | ||
2086 | |||
2087 | .EXAMP LE | ||
2088 | Re name-List -spWeb $su bWeb -list Name "RDC Calendar" -newTitle "RDC Calen dar_bak" | ||
2089 | |||
2090 | #> | ||
2091 | |||
2092 | ForEac h($culture in $spWeb .Supported UICultures ) { | ||
2093 | [S ystem.Thre ading.Thre ad]::Curre ntThread.C urrentUICu lture=$cul ture; | ||
2094 | #c heck if th e list has already b een named or not | ||
2095 | if (($spWeb.L ists.TryGe tList($new Title)) -e q $null) { | ||
2096 | $list = $spWeb.Lis ts.TryGetL ist($listN ame) | ||
2097 | $list.Ti tle = $new title; | ||
2098 | $list.Ro otFolder.M oveTo($new title) | ||
2099 | $list.Up date(); | ||
2100 | } | ||
2101 | } | ||
2102 | $spWeb .Dispose() | ||
2103 | } | ||
2104 | |||
2105 | function C lone-Calen dar($spWeb , $calName ,$OldCalNa me, $calTi tle) { | ||
2106 | <# | ||
2107 | |||
2108 | .SYNOP SIS | ||
2109 | Co pies a cal endar temp late to cr eate a new calendar. | ||
2110 | |||
2111 | .DESCR IPTION | ||
2112 | Ch ecks to se e if a cal endar with calTitle exists and deletes i t. Creates a new cal endar base on the Ca lendar Lis t Template . Adds the same colu mns from t he old cal endar | ||
2113 | to the new c alendar. B uilds the views for display an d editing. Finally, migrates t he data fr om the old calendar list to th e new cale ndar list. | ||
2114 | |||
2115 | .PARAM ETER spWeb | ||
2116 | [M icrosoft.S harePoint. SPWeb] The SPWeb of the site c ollection or facilit y subsite. | ||
2117 | |||
2118 | .PARAM ETER calNa me | ||
2119 | [S tring] The new name of the cal endar list . | ||
2120 | |||
2121 | .PARAM ETER OldCa lName | ||
2122 | [S tring] The name of t he backup list to co py data fr om. Probab ly created using Ren ame-List. | ||
2123 | |||
2124 | .PARAM ETER calTi tle | ||
2125 | [S tring] Tit le of the new list. | ||
2126 | |||
2127 | .NOTES | ||
2128 | No t used in RAMS-2.3.0 | ||
2129 | |||
2130 | .EXAMP LE | ||
2131 | Cl one-Calend ar -spWeb $subWeb -c alName "RD CCalendar" -OldCalNa me "RDC Ca lendar_bak " -calTitl e "RDC Cal endar" | ||
2132 | |||
2133 | #> | ||
2134 | |||
2135 | $SPTem plate = (G et-SiteWeb ).ListTemp lates["Cal endar"] | ||
2136 | |||
2137 | $newCa l = $spWeb .Lists.Try GetList($c alTitle) | ||
2138 | #remov e if the c lone list already ex ist | ||
2139 | if($ne wCal -ne $ null) { | ||
2140 | $s pWeb.Lists .Delete($n ewCal.ID) | ||
2141 | $s pWeb.Updat e() | ||
2142 | } | ||
2143 | #creat e a new cl one list | ||
2144 | $spWeb .Lists.Add ($calTitle ,$calTitle ,$SPTempla te) | ||
2145 | $spWeb .Update() | ||
2146 | |||
2147 | #get o ld list (a fter renam e) | ||
2148 | $oldLi st = $spWe b.Lists.Tr yGetList($ OldCalName ) | ||
2149 | |||
2150 | #get n ew list | ||
2151 | $newLi st = $spWe b.Lists.Tr yGetList($ calTitle) | ||
2152 | |||
2153 | if($ol dList -ne $null) { | ||
2154 | |||
2155 | fo reach($old Fld in $ol dList.Fiel ds) { | ||
2156 | if(($new List.Field s.Contains FieldWithS taticName( $oldFld.St aticName) -eq $False ) -and | ||
2157 | ( $newList.F ields.Cont ainsField( $oldFld.Ti tle) -eq $ False)) { | ||
2158 | $new List.Field s.Add($old Fld); | ||
2159 | $new List.Updat e() | ||
2160 | writ e-log -mes sage "$old Fld has be en added t o $newList " -Console Foreground Green | ||
2161 | } else { | ||
2162 | writ e-log -mes sage "$old Fld alread y exist in $newList" -ConsoleF oreground Yellow | ||
2163 | } | ||
2164 | } | ||
2165 | |||
2166 | $s pWeb.Updat e() | ||
2167 | #s et default view | ||
2168 | $n ewView = $ newList.Vi ews | ? { $_.Title - eq 'All Ev ents' }; | ||
2169 | |||
2170 | <# add old vi ew | ||
2171 | $o ldView = $ oldList.Vi ews | ? { $_.Title - eq 'All Ev ents' }; | ||
2172 | #s et default view | ||
2173 | $n ewView = $ newList.Vi ews | ? { $_.Title - eq 'All Ev ents' }; | ||
2174 | #c lone view fields | ||
2175 | fo reach($old ViewFld in $oldView. ViewFields ){ | ||
2176 | if($newV iew.ViewFi elds.exist s($oldView Fld)) { | ||
2177 | writ e-log -mes sage "$($o ldViewFld) already e xist in $n ewView" -C onsoleFore ground Yel low | ||
2178 | } | ||
2179 | else { | ||
2180 | $new View.ViewF ields.Add( $oldViewFl d) | ||
2181 | writ e-log -mes sage "$($o ldViewFld) has been added to $ newView" - ConsoleFor eground Gr een | ||
2182 | } | ||
2183 | } | ||
2184 | #> | ||
2185 | $c ontentType = "Event" | ||
2186 | $n ewFieldOrd er = @("Ti tle", "Eve ntDate", " EndDate", "Location" , "fAllDay Event", "f Recurrence ","EventAt tendees", "EventComm itteeAtten dees", "P articipant sPicker"," Administra tive_x0020 _Items", " TaxKeyword ", "Approv edApplicat ionLookup" , "IACUCMe etingMinut eLookup", "RDCMeetin gMinuteLoo kup", "Dec ision", | ||
2187 | "D eliberatio n" | ||
2188 | ) | ||
2189 | $c t = $newLi st.Content Types[$con tentType] | ||
2190 | $c t.FieldLin ks.Reorder ($newField Order) | ||
2191 | $c t.Update() | ||
2192 | $n ewList.Upd ate() | ||
2193 | #s et as defa ult view | ||
2194 | $n ewView.Def aultView = $true | ||
2195 | $n ewView.Upd ate() | ||
2196 | #m igrate dat a from old list to n ew list | ||
2197 | $n ewItem = $ null | ||
2198 | fo reach($old Item in $o ldList.Ite ms) { | ||
2199 | $newItem = $newLis t.AddItem( ) | ||
2200 | foreach( $fld in $o ldItem.Fie lds) { | ||
2201 | if(($n ewList.Fie lds.Contai nsField($f ld.Title) -eq $True) ) { | ||
2202 | if(" ID","WF"," Link","_", "Agenda"," Attachment s","Facili ties" -not contains $ fld.Static Name){ | ||
2203 | if($fld.Re adOnlyFiel d -eq $Fal se) { | ||
2204 | $newIt em[$fld.St aticName] = $oldItem [$fld.Stat icName] | ||
2205 | write- log -messa ge "Item: $($newItem [$fld.Stat icName]) h as been ad ded to the $newList" -ConsoleF oreground Cyan | ||
2206 | } | ||
2207 | } | ||
2208 | } | ||
2209 | } | ||
2210 | $newItem .Update() | ||
2211 | } | ||
2212 | $n ewList.Upd ate() | ||
2213 | } | ||
2214 | } | ||
2215 | |||
2216 | function R emove-Site Pages ([st ring[]]$si tePages) { | ||
2217 | <# | ||
2218 | |||
2219 | .SYNOP SIS | ||
2220 | Re moves item s from the SitePages folder in SharePoin t. | ||
2221 | |||
2222 | .DESCR IPTION | ||
2223 | Lo ops throug h the page s in site pages and if the req uested pag e is found , deletes it. | ||
2224 | |||
2225 | .PARAM ETER siteP ages | ||
2226 | [S tring[]] T he names o f the page to remove . | ||
2227 | |||
2228 | .EXAMP LE | ||
2229 | Re move-SiteP ages -site Pages mana geCommitte e.html | ||
2230 | |||
2231 | .EXAMP LE | ||
2232 | Re move-SiteP ages -site Pages mana geCommitte e.html, an otherPage. aspx | ||
2233 | |||
2234 | #> | ||
2235 | |||
2236 | foreac h($page in $sitepage s) { | ||
2237 | $t argetPage = ((Get-Si teWeb).Lis ts["Site P ages"]).It ems | ? {$ _.Name -eq $page} | ||
2238 | if ($targetPa ge -ne $Nu ll) { | ||
2239 | $targetP age.Delete () | ||
2240 | write-lo g -message "$page ha s been del eted from Site Colle ction: $(G et-SiteWeb )" -Consol eForegroun d Yellow | ||
2241 | } | ||
2242 | } | ||
2243 | } | ||
2244 | |||
2245 | function R emove-Site Assets ([s tring[]]$s iteAssets) { | ||
2246 | <# | ||
2247 | |||
2248 | .SYNOP SIS | ||
2249 | Re moves item s from the SiteAsset s folder i n SharePoi nt. | ||
2250 | |||
2251 | .DESCR IPTION | ||
2252 | Lo ops throug h the item s in site assets and if the re quested it em is foun d, deletes it. | ||
2253 | |||
2254 | .PARAM ETER siteA ssets | ||
2255 | [S tring[]] T he names o f the item to remove . | ||
2256 | |||
2257 | .NOTES | ||
2258 | No t used in RAMS-2.3.0 | ||
2259 | |||
2260 | .EXAMP LE | ||
2261 | Re move-SiteP ages -site Pages mana geCommitte e.html | ||
2262 | |||
2263 | .EXAMP LE | ||
2264 | Re move-SiteP ages -site Pages mana geCommitte e.html, an otherPage. aspx | ||
2265 | |||
2266 | #> | ||
2267 | |||
2268 | foreac h($asset i n $siteass ets) { | ||
2269 | $t argetAsset = ((Get-S iteWeb).Li sts["Site Assets"]). Items | ? {$_.Name - eq $asset} | ||
2270 | if ($targetAs set -ne $N ull) { | ||
2271 | $targetA sset.Delet e() | ||
2272 | write-lo g -message "$asset h as been de leted from Site Coll ection: $( Get-SiteWe b)" -Conso leForegrou nd Yellow | ||
2273 | } | ||
2274 | } | ||
2275 | } | ||
2276 | |||
2277 | function R emove-Faci litySitePa ges ([stri ng[]]$site Pages) { | ||
2278 | <# | ||
2279 | |||
2280 | .SYNOP SIS | ||
2281 | Re moves item s from the SitePages folder ea ch facilit y subsite. | ||
2282 | |||
2283 | .DESCR IPTION | ||
2284 | Lo ops throug h the page s in site pages and if the req uested pag e is found , deletes it. | ||
2285 | |||
2286 | .PARAM ETER siteP ages | ||
2287 | [S tring[]] T he names o f the page to remove . | ||
2288 | |||
2289 | .NOTES | ||
2290 | No t used in RAMS-2.3.0 | ||
2291 | |||
2292 | .EXAMP LE | ||
2293 | Re move-Facil itySitePag es -sitePa ges manage Committee. html | ||
2294 | |||
2295 | .EXAMP LE | ||
2296 | Re move-Facil itySitePag es -sitePa ges manage Committee. html | ||
2297 | |||
2298 | #> | ||
2299 | |||
2300 | foreac h ($subWeb in (Get-S iteWeb).We bs) { | ||
2301 | fo reach($pag e in $site pages) { | ||
2302 | $targetP age = ($su bWeb.Lists ["Site Pag es"]).Item s | ? {$_. Name -eq $ page} | ||
2303 | if($targ etPage -ne $Null) { | ||
2304 | $tar getPage.De lete() | ||
2305 | writ e-log -mes sage "$($t argetPage. Name) has been delet ed from $s ubWeb" -Co nsoleForeg round Yell ow | ||
2306 | } | ||
2307 | } | ||
2308 | } | ||
2309 | } | ||
2310 | |||
2311 | function R emove-Faci litySiteAs sets ([str ing[]]$sit eAssets) { | ||
2312 | <# | ||
2313 | |||
2314 | .SYNOP SIS | ||
2315 | Re moves item s from the SiteAsset s folder e ach facili ty subsite . | ||
2316 | |||
2317 | .DESCR IPTION | ||
2318 | Lo ops throug h the item s in site assets and if the re quested it em is foun d, deletes it. | ||
2319 | |||
2320 | .PARAM ETER siteA ssets | ||
2321 | [S tring[]] T he names o f the item to remove . | ||
2322 | |||
2323 | .NOTES | ||
2324 | No t used in RAMS-2.3.0 | ||
2325 | |||
2326 | .EXAMP LE | ||
2327 | Re move-Facil itySiteAss ets -siteA ssets mana geCommitte e.html | ||
2328 | |||
2329 | .EXAMP LE | ||
2330 | Re move-Facil itySitePag es -sitePa ges manage Committee. html, anot herPage.as px | ||
2331 | |||
2332 | #> | ||
2333 | |||
2334 | foreac h ($subWeb in (Get-S iteWeb).We bs) { | ||
2335 | fo reach($ass et in $sit eassets) { | ||
2336 | $targetA sset = ($s ubWeb.List s["Site As sets"]).It ems | ? {$ _.Name -eq $asset} | ||
2337 | if($targ etAsset -n e $Null) { | ||
2338 | $tar getAsset.D elete() | ||
2339 | writ e-log -mes sage "$($t argetAsset .Name) has been dele ted from $ subWeb" -C onsoleFore ground Yel low | ||
2340 | } | ||
2341 | } | ||
2342 | } | ||
2343 | } | ||
2344 | |||
2345 | function N ew-SpListV iew ([Syst em.Collect ions.Speci alized.Str ingCollect ion] $fldL ist, $view Title, $li stName,$vi ewQuery,$v iewRowLimi t) { | ||
2346 | <# | ||
2347 | |||
2348 | .SYNOP SIS | ||
2349 | Cr eate a Lis t view for a given l ist. | ||
2350 | |||
2351 | .DESCR IPTION | ||
2352 | Bu ilds a lis t view by retrieving the list, creating a view wit h the prov ided name, adding th e provided fields an d updating the list. | ||
2353 | |||
2354 | .PARAM ETER fldLi st | ||
2355 | [S tring[]] T he list of fields. | ||
2356 | |||
2357 | .PARAM ETER viewT itle | ||
2358 | [S tring] The names of the view. | ||
2359 | |||
2360 | .PARAM ETER listN ame | ||
2361 | [S tring] The names of the list. | ||
2362 | |||
2363 | .PARAM ETER viewQ uery | ||
2364 | [S tring] The query. | ||
2365 | |||
2366 | .PARAM ETER viewR owLimit | ||
2367 | [S tring[]] T he number of rows to include i n the view . | ||
2368 | |||
2369 | .EXAMP LE | ||
2370 | $f ldList = @ ('StudyTit le'; | ||
2371 | 'StudyID Link'; | ||
2372 | 'Princip alInvestig ator'; | ||
2373 | 'IRBAdmi nistrator' ; | ||
2374 | 'Applica tionStatus '; | ||
2375 | 'Modifie d'; | ||
2376 | 'Applica tionSiteTy pe'; | ||
2377 | 'Facilit iesLookup' ; | ||
2378 | 'Adverse Reportable Event'; | ||
2379 | 'Deviati onReportab leEvent' | ||
2380 | ) | ||
2381 | $v iewQuery = "<Where><A nd><Contai ns><FieldR ef Name='S tudyTitle' /><Value T ype='Text' >Adverse/R eportable Event</Val ue></Conta ins>" | ||
2382 | +"<Neq>< FieldRef N ame='Appli cationStat us'/><Valu e Type='Te xt'>Draft< /Value></N eq></And>< /Where>" | ||
2383 | Ne w-SpListVi ew -fldLis t $fldList -viewTitl e 'Adverse Reportable Event' -li stName 'Ap plication' -viewQuer y $viewQue ry -viewRo wLimit '50 ' | ||
2384 | |||
2385 | #> | ||
2386 | |||
2387 | |||
2388 | #Get d estination site and list | ||
2389 | $web = Get-SiteW eb | ||
2390 | $list = $web.Get List($web. ServerRela tiveUrl.Tr imEnd("/") + "/Lists /$listName ") | ||
2391 | |||
2392 | #Title property | ||
2393 | $viewT itle = $vi ewTitle | ||
2394 | $View = $list.Vi ews | ? {$ _.Title -m atch $view Title} | ||
2395 | if ($V iew -ne $n ull) { | ||
2396 | $list.Vie ws.Delete( $View.ID) | ||
2397 | $list.Upd ate() | ||
2398 | } | ||
2399 | #A dd the col umn names from the V iewField p roperty to a string collection | ||
2400 | $viewF ields = Ne w-Object S ystem.Coll ections.Sp ecialized. StringColl ection | ||
2401 | foreac h ($fldNam e in $fldL ist) { | ||
2402 | $v iewFields. Add($fldNa me) > $nul l | ||
2403 | } | ||
2404 | |||
2405 | #Paged property | ||
2406 | $viewP aged = $tr ue | ||
2407 | |||
2408 | #Defau ltView pro perty | ||
2409 | $viewD efaultView = $false | ||
2410 | |||
2411 | #Creat e the view in the de stination list | ||
2412 | $newvi ew = $list .Views.Add ($viewTitl e, $viewFi elds, $vie wQuery, $v iewRowLimi t, $viewPa ged, $view DefaultVie w) | ||
2413 | write- log -messa ge "$($new view.Title ) view has been adde d to the $ ($list.Tit le) list o n site $($ web.Url)" -consoleFo reground G reen | ||
2414 | |||
2415 | #updat e view and list | ||
2416 | $newvi ew.Update( ) | ||
2417 | $list. Update() | ||
2418 | } | ||
2419 | |||
2420 | function N ew-SpFacil ityListVie w ($web, [ System.Col lections.S pecialized .StringCol lection] $ fldList, $ viewTitle, $listName ,$viewQuer y,$viewRow Limit) { | ||
2421 | <# | ||
2422 | |||
2423 | .SYNOP SIS | ||
2424 | Cr eate a Lis t view for a given l ist on eac h facility subsite. | ||
2425 | |||
2426 | .DESCR IPTION | ||
2427 | Bu ilds a lis t view for each faci lity list by retriev ing the li st, creati ng a view with the p rovided na me, adding the provi ded fields and updat ing the li st. | ||
2428 | |||
2429 | .PARAM ETER fldLi st | ||
2430 | [S tring[]] T he list of fields. | ||
2431 | |||
2432 | .PARAM ETER viewT itle | ||
2433 | [S tring] The names of the view. | ||
2434 | |||
2435 | .PARAM ETER listN ame | ||
2436 | [S tring] The names of the list. | ||
2437 | |||
2438 | .PARAM ETER viewQ uery | ||
2439 | [S tring] The query. | ||
2440 | |||
2441 | .PARAM ETER viewR owLimit | ||
2442 | [S tring[]] T he number of rows to include i n the view . | ||
2443 | |||
2444 | .EXAMP LE | ||
2445 | $f ldList = @ ('LinkTitl e'; | ||
2446 | 'EventDa te'; | ||
2447 | 'EndDate '; | ||
2448 | 'Locatio n'; | ||
2449 | 'Attende es'; | ||
2450 | 'Committ eeAttendee s' | ||
2451 | ) | ||
2452 | $v iewQuery = "<Where>< /Where>" | ||
2453 | Ne w-SpFacili tyListView -web $we b -fldList $fldList -viewTitle 'Standard View' -lis tName 'Ful lBoardRevi ewCalendar ' -viewQue ry $viewQu ery -viewR owLimit '5 0' | ||
2454 | |||
2455 | |||
2456 | #> | ||
2457 | |||
2458 | $list = $web.Get List($web. ServerRela tiveUrl.Tr imEnd("/") + "/Lists /$listName ") | ||
2459 | |||
2460 | #Title property | ||
2461 | $viewT itle = $vi ewTitle | ||
2462 | $View = $list.Vi ews | ? {$ _.Title -m atch $view Title} | ||
2463 | if ($V iew -ne $n ull) { | ||
2464 | $list.Vie ws.Delete( $View.ID) | ||
2465 | $list.Upd ate() | ||
2466 | } | ||
2467 | #A dd the col umn names from the V iewField p roperty to a string collection | ||
2468 | $viewF ields = Ne w-Object S ystem.Coll ections.Sp ecialized. StringColl ection | ||
2469 | foreac h ($fldNam e in $fldL ist) { | ||
2470 | $v iewFields. Add($fldNa me) > $nul l | ||
2471 | } | ||
2472 | |||
2473 | #Paged property | ||
2474 | $viewP aged = $tr ue | ||
2475 | |||
2476 | #Defau ltView pro perty | ||
2477 | $viewD efaultView = $false | ||
2478 | |||
2479 | #Creat e the view in the de stination list | ||
2480 | $newvi ew = $list .Views.Add ($viewTitl e, $viewFi elds, $vie wQuery, $v iewRowLimi t, $viewPa ged, $view DefaultVie w) | ||
2481 | write- log -messa ge "$viewT itle View has been a dded to th e $listNam e list on site $($we b.Url)" -C onsoleFore ground Gre en | ||
2482 | |||
2483 | #updat e view and list | ||
2484 | $newvi ew.Update( ) | ||
2485 | $list. Update() | ||
2486 | } | ||
2487 | |||
2488 | function U pdate-SpLi stView ([S ystem.Coll ections.Sp ecialized. StringColl ection] $f ldList, $l istName) { | ||
2489 | <# | ||
2490 | |||
2491 | .SYNOP SIS | ||
2492 | Ad ds fields to each vi ew on a gi ven list | ||
2493 | |||
2494 | .DESCR IPTION | ||
2495 | Lo ops throug h each vie w on a giv en list an d adds the fields sp ecified in fldList | ||
2496 | |||
2497 | .PARAM ETER fldLi st | ||
2498 | [S tring[]] T he list of fields. | ||
2499 | |||
2500 | .PARAM ETER listN ame | ||
2501 | [S tring] The names of the list. | ||
2502 | |||
2503 | .EXAMP LE | ||
2504 | $f ldList = @ ('LocalSit eLiaisons' ;'LocalSit eAdministr ators') | ||
2505 | Up date-SpLis tView -fld List $fldL ist -listN ame 'Facil ity' | ||
2506 | |||
2507 | #> | ||
2508 | |||
2509 | #Get d estination site and list | ||
2510 | $web = Get-SiteW eb | ||
2511 | $list = $web.Get List($web. ServerRela tiveUrl.Tr imEnd("/") + "/Lists /$listName ") | ||
2512 | |||
2513 | #Updat e Views | ||
2514 | try { | ||
2515 | fo reach($Vie w in $list .Views) { | ||
2516 | #Add the column na mes from t he ViewFie ld propert y to a str ing collec tion | ||
2517 | $viewFie lds = $Vie w.ViewFiel ds | ||
2518 | foreach ($fldName in $fldLis t) { | ||
2519 | $Vie wFields.Ad d($fldName ) > $null | ||
2520 | } | ||
2521 | #update view and l ist | ||
2522 | $View.Up date() | ||
2523 | write-lo g -message "$($View. Title) Vie w has been updated f or the $($ list.Title ) list on site $($we b.Url)" -C onsoleFore ground Gre en | ||
2524 | } | ||
2525 | } catch { | ||
2526 | #do nothing. | ||
2527 | } final ly { | ||
2528 | $li st.Update( ) | ||
2529 | } | ||
2530 | } | ||
2531 | |||
2532 | Function R emove-Cont entTypeFro mList() { | ||
2533 | <# | ||
2534 | |||
2535 | .SYNOP SIS | ||
2536 | Re moves a co ntent type from a gi ven list. | ||
2537 | |||
2538 | .DESCR IPTION | ||
2539 | NO T USED bec ause it do es not wor k as writt en. When t rying to r emove the columns, t he data ne eds to be deleted fi rst??? See notes in UpdateFaci lityInfo.p s1. | ||
2540 | |||
2541 | .PARAM ETER SiteU RL | ||
2542 | [S tring] The site URL. | ||
2543 | |||
2544 | .PARAM ETER ListN ame | ||
2545 | [S tring] The names of the list. | ||
2546 | |||
2547 | .PARAM ETER Conte ntTypeName | ||
2548 | [S tring] The names of the conten t type to remove . | ||
2549 | |||
2550 | .NOTES | ||
2551 | No t used in RAMS-2.3.0 | ||
2552 | Do es not wor k. | ||
2553 | |||
2554 | .EXAMP LE | ||
2555 | Re move-Conte ntTypeFrom List -Site URL (Get-S iteURL) -L istName "F acility" - ContentTyp eName "Fac ility CT" -Verbose | ||
2556 | |||
2557 | #> | ||
2558 | |||
2559 | param( | ||
2560 | [P arameter(M andatory=$ true)] [st ring] $Sit eURL, | ||
2561 | [P arameter(M andatory=$ true)] [st ring] $Lis tName, | ||
2562 | [P arameter(M andatory=$ true)] [st ring] $Con tentTypeNa me | ||
2563 | ) | ||
2564 | |||
2565 | try { | ||
2566 | |||
2567 | Ad d-Type -Pa th "C:\Pro gram Files \Common Fi les\Micros oft Shared \Web Serve r Extensio ns\15\ISAP I\Microsof t.SharePoi nt.Client. Runtime.dl l" | ||
2568 | Ad d-Type -Pa th "C:\Pro gram Files \Common Fi les\Micros oft Shared \Web Serve r Extensio ns\15\ISAP I\Microsof t.SharePoi nt.Client. dll" | ||
2569 | |||
2570 | $Credentia ls = New-O bject Syst em.Net.Net workCreden tial("RAMI NTSPFARM", "&35Dkc>Av +KX"," DN S ") | ||
2571 | |||
2572 | #S etup the c ontext | ||
2573 | $C tx = New-O bject Micr osoft.Shar ePoint.Cli ent.Client Context($S iteURL) | ||
2574 | $C tx.Credent ials = $Cr edentials | ||
2575 | |||
2576 | #G et the Lis t | ||
2577 | $L ist = $Ctx .Web.Lists .GetByTitl e($ListNam e) | ||
2578 | $C tx.Load($L ist) | ||
2579 | |||
2580 | #G et the con tent type from list | ||
2581 | $C ontentType Coll = $Li st.Content Types | ||
2582 | $C tx.Load($C ontentType Coll) | ||
2583 | $C tx.Execute Query() | ||
2584 | |||
2585 | #G et the con tent type to remove | ||
2586 | $C TypeToRemo ve = $Cont entTypeCol l | Where {$_.Name - eq $Conten tTypeName} | ||
2587 | If ($CTypeToR emove -ne $Null) | ||
2588 | { | ||
2589 | #Remove content ty pe from li st | ||
2590 | $CTypeTo Remove.Del eteObject( ) | ||
2591 | $Ctx.Exe cuteQuery( ) | ||
2592 | |||
2593 | write-lo g -message "Content Type '$Con tentTypeNa me' Remove d From '$L istName'" -consoleFo reground Green | ||
2594 | } | ||
2595 | el se | ||
2596 | { | ||
2597 | write-lo g -message "Content Type '$Con tentTypeNa me' doesn' t exists i n '$ListNa me'" -cons oleForegro und Yello w | ||
2598 | Return | ||
2599 | } | ||
2600 | } catch { | ||
2601 | wr ite-log -m essage "Er ror Removi ng Content Type from List! $($ _.Exceptio n.Message) " -console Foreground Red | ||
2602 | if ($($_.Exc eption.Err orRecord)) { write-l og -messag e "$($_.Ex ception.Er rorRecord) " -console Foreground Red } | ||
2603 | if ($($_.Exc eption.sta cktrace)) { write-lo g -message "$($_.Exc eption.sta cktrace)" -consoleFo reground R ed } | ||
2604 | if ($($_.Scr iptStackTr ace)) { wr ite-log -m essage "$( $_.ScriptS tackTrace) " -console Foreground Red } | ||
2605 | } | ||
2606 | } | ||
2607 | |||
2608 | function C opy-SpList ($spWeb, $ calName,$O ldCalName, $calTitle ) { | ||
2609 | <# | ||
2610 | |||
2611 | .SYNOP SIS | ||
2612 | Co pies a cal endar temp late to cr eate a new calendar. | ||
2613 | |||
2614 | .DESCR IPTION | ||
2615 | Ch ecks to se e if a cal endar with calTitle exists and deletes i t. Creates a new cal endar base on the Ca lendar Lis t Template . Adds the same colu mns from t he old cal endar | ||
2616 | to the new c alendar. B uilds the views for display an d editing. Finally, migrates t he data fr om the old calendar list to th e new cale ndar list. | ||
2617 | |||
2618 | .PARAM ETER spWeb | ||
2619 | [M icrosoft.S harePoint. SPWeb] The SPWeb of the site c ollection or facilit y subsite. | ||
2620 | |||
2621 | .PARAM ETER calNa me | ||
2622 | [S tring] The new name of the cal endar list . | ||
2623 | |||
2624 | .PARAM ETER OldCa lName | ||
2625 | [S tring] The name of t he backup list to co py data fr om. Probab ly created using Ren ame-List. | ||
2626 | |||
2627 | .PARAM ETER calTi tle | ||
2628 | [S tring] Tit le of the new list. | ||
2629 | |||
2630 | .NOTES | ||
2631 | No t used in RAMS-2.3.0 | ||
2632 | |||
2633 | .EXAMP LE | ||
2634 | Cl one-Calend ar -spWeb $subWeb -c alName "RD CCalendar" -OldCalNa me "RDC Ca lendar_bak " -calTitl e "RDC Cal endar" | ||
2635 | |||
2636 | #> | ||
2637 | |||
2638 | $SPTem plate = (G et-SiteWeb ).ListTemp lates["Cal endar"] | ||
2639 | |||
2640 | $newCa l = $spWeb .Lists.Try GetList($c alTitle) | ||
2641 | #remov e if the c lone list already ex ist | ||
2642 | if($ne wCal -ne $ null) { | ||
2643 | $s pWeb.Lists .Delete($n ewCal.ID) | ||
2644 | $s pWeb.Updat e() | ||
2645 | } | ||
2646 | #creat e a new cl one list | ||
2647 | $spWeb .Lists.Add ($calTitle ,$calTitle ,$SPTempla te) | ||
2648 | $spWeb .Update() | ||
2649 | |||
2650 | #get o ld list (a fter renam e) | ||
2651 | $oldLi st = $spWe b.Lists.Tr yGetList($ OldCalName ) | ||
2652 | |||
2653 | #get n ew list | ||
2654 | $newLi st = $spWe b.Lists.Tr yGetList($ calTitle) | ||
2655 | |||
2656 | if($ol dList -ne $null) { | ||
2657 | |||
2658 | fo reach($old Fld in $ol dList.Fiel ds) { | ||
2659 | if(($new List.Field s.Contains FieldWithS taticName( $oldFld.St aticName) -eq $False ) -and | ||
2660 | ( $newList.F ields.Cont ainsField( $oldFld.Ti tle) -eq $ False)) | ||
2661 | { | ||
2662 | $new List.Field s.Add($old Fld); | ||
2663 | $new List.Updat e() | ||
2664 | writ e-log -mes sage "$old Fld has be en added t o $newList " -Console Foreground Green | ||
2665 | } | ||
2666 | else { | ||
2667 | writ e-log -mes sage "$old Fld alread y exist in $newList" -ConsoleF oreground Yellow | ||
2668 | } | ||
2669 | } | ||
2670 | |||
2671 | $s pWeb.Updat e() | ||
2672 | #s et default view | ||
2673 | $n ewView = $ newList.Vi ews | ? { $_.Title - eq 'All Ev ents' }; | ||
2674 | |||
2675 | <# add old vi ew | ||
2676 | $o ldView = $ oldList.Vi ews | ? { $_.Title - eq 'All Ev ents' }; | ||
2677 | #s et default view | ||
2678 | $n ewView = $ newList.Vi ews | ? { $_.Title - eq 'All Ev ents' }; | ||
2679 | #c lone view fields | ||
2680 | fo reach($old ViewFld in $oldView. ViewFields ){ | ||
2681 | if($newV iew.ViewFi elds.exist s($oldView Fld)) { | ||
2682 | writ e-log -mes sage "$old ViewFld al ready exis t in $newV iew" -Cons oleForegro und Yellow | ||
2683 | } | ||
2684 | else { | ||
2685 | $new View.ViewF ields.Add( $oldViewFl d) | ||
2686 | writ e-log -mes sage "$old ViewFld ha s been add ed to $new View" -Con soleForegr ound Green | ||
2687 | } | ||
2688 | } | ||
2689 | #> | ||
2690 | $c ontentType = "Event" | ||
2691 | $n ewFieldOrd er = @("Ti tle", "Eve ntDate", " EndDate", "Location" , "fAllDay Event", "f Recurrence ","EventAt tendees", "EventComm itteeAtten dees", "P articipant sPicker"," Administra tive_x0020 _Items", " TaxKeyword ", "Approv edApplicat ionLookup" , "IACUCMe etingMinut eLookup", "RDCMeetin gMinuteLoo kup", "Dec ision", | ||
2692 | "D eliberatio n" | ||
2693 | ) | ||
2694 | $c t = $newLi st.Content Types[$con tentType] | ||
2695 | $c t.FieldLin ks.Reorder ($newField Order) | ||
2696 | $c t.Update() | ||
2697 | $n ewList.Upd ate() | ||
2698 | #s et as defa ult view | ||
2699 | $n ewView.Def aultView = $true | ||
2700 | $n ewView.Upd ate() | ||
2701 | #m igrate dat a from old list to n ew list | ||
2702 | $n ewItem = $ null | ||
2703 | fo reach($old Item in $o ldList.Ite ms) { | ||
2704 | $newItem = $newLis t.AddItem( ) | ||
2705 | foreach( $fld in $o ldItem.Fie lds) { | ||
2706 | if(($n ewList.Fie lds.Contai nsField($f ld.Title) -eq $True) ) { | ||
2707 | if(" ID","WF"," Link","_", "Agenda"," Attachment s","Facili ties" -not contains $ fld.Static Name){ | ||
2708 | if($fld.Re adOnlyFiel d -eq $Fal se) { | ||
2709 | $newIt em[$fld.St aticName] = $oldItem [$fld.Stat icName] | ||
2710 | write- log -messa ge "Item: $($newItem [$fld.Stat icName]) h as been ad ded to the $newList" -ConsoleF oreground Cyan | ||
2711 | } | ||
2712 | } | ||
2713 | } | ||
2714 | } | ||
2715 | $newItem .Update() | ||
2716 | } | ||
2717 | $n ewList.Upd ate() | ||
2718 | } | ||
2719 | } | ||
2720 | |||
2721 | function R emove-Colu mnFromList ($WebURL, $ListName , $ColumnN ame) { | ||
2722 | <# | ||
2723 | |||
2724 | .SYNOP SIS | ||
2725 | Re moves a co lumn from a given li st. | ||
2726 | |||
2727 | .DESCR IPTION | ||
2728 | Ge ts the web and list, then loop s through to find th e field to remove. W hen found, reset the attribute s to allow deletion and then d elete the field. | ||
2729 | |||
2730 | .PARAM ETER WebUR L | ||
2731 | [S tring] The site URL. | ||
2732 | |||
2733 | .PARAM ETER ListN ame | ||
2734 | [S tring] The names of the list. | ||
2735 | |||
2736 | .PARAM ETER Colum nName | ||
2737 | [S tring] The names of the column to remove . | ||
2738 | |||
2739 | .EXAMP LE | ||
2740 | Re move-Colum nFromList -WebURL (G et-SiteURL ) -ListNam e "Facilit y" -Column Name $_.Ti tle | ||
2741 | |||
2742 | #> | ||
2743 | |||
2744 | #Get I nternal Na me of the columns | ||
2745 | $web = Get-SPWeb $WebURL | ||
2746 | |||
2747 | #Get t he list | ||
2748 | $list = $web.Lis ts.TryGetL ist($ListN ame) | ||
2749 | |||
2750 | if($Li st -ne $nu ll) { | ||
2751 | #G et the col umn | ||
2752 | $l ist.Fields | ? {$_.T itle -matc h $ColumnN ame} | % { | ||
2753 | #Reset c olumn prop erties to allow dele te | ||
2754 | #$_.Hidd en = $Fals e | ||
2755 | $_.ReadO nlyField = $False | ||
2756 | $_.Allow Deletion = $True | ||
2757 | $_.Updat e() | ||
2758 | #Delete the column from list | ||
2759 | $list.Fi elds.Delet e($_) | ||
2760 | write-lo g -message ("Column " + $_.Tit le + " has been dele ted!") -f Magenta | ||
2761 | } | ||
2762 | } else { | ||
2763 | wr ite-log -m essage "Sp ecified Li st is not found!" -c onsoleFore ground Yel low | ||
2764 | } | ||
2765 | } | ||
2766 | |||
2767 | function S et-SiteCol umnLookup ($web, $co lName,$col StaticName , $lookupL istName,$l ookupColum nName) { | ||
2768 | <# | ||
2769 | |||
2770 | .SYNOP SIS | ||
2771 | Cr eates a lo okup colum n on a lis t. | ||
2772 | |||
2773 | .DESCR IPTION | ||
2774 | Cr eates a lo okup colum n from the lookupLis tName usin g the Id a nd lookupC olumnTitle . | ||
2775 | |||
2776 | .PARAM ETER colNa me | ||
2777 | [S tring] The display n ame of the new Looku p column. | ||
2778 | |||
2779 | .PARAM ETER colSt aticName | ||
2780 | [S tring] The static na me of the new Lookup column. T ypically t he same as the displ ay name wi thout spac es. Will a lso be use d as the i nternal na me. | ||
2781 | |||
2782 | .PARAM ETER looku pListName | ||
2783 | [S tring] The list that is the so urce of th e data to be looked up. | ||
2784 | |||
2785 | .PARAM ETER looku pColumnNam e | ||
2786 | [S tring] The column to be displa yed in the lookup co lumn dropd own list. | ||
2787 | |||
2788 | .EXAMP LE | ||
2789 | Se t-SiteColu mnLookup - web $web - colName "F acilities Lookup" -c olStaticNa me "Facili tiesLookup " -lookupL istName "F acilities" -lookupCo lumnName " Title" | ||
2790 | |||
2791 | #> | ||
2792 | |||
2793 | #$web = Get-Site Web | ||
2794 | $looku pList = $w eb.Lists[$ lookupList Name] | ||
2795 | $web.F ields.AddL ookup($col StaticName , $lookupL ist.ID,$fa lse); | ||
2796 | $field = $web.Fi elds[$colS taticName] | ||
2797 | $field .LookupFie ld = $look upColumnNa me | ||
2798 | $field .Title = $ colName | ||
2799 | $field .Update() | ||
2800 | } | ||
2801 | |||
2802 | function S et-Facilit yListPermi ssionAndVe rsioning ( $listTitle ,[Microsof t.SharePoi nt.SPMembe r]$securit yMember,[M icrosoft.S harePoint. SPRights]$ permission Mask, [swi tch] $enab leVersioni ng) { | ||
2803 | <# | ||
2804 | |||
2805 | .SYNOP SIS | ||
2806 | Fo r a given list set t he permiss ions and t urn versio ning on | ||
2807 | |||
2808 | .DESCR IPTION | ||
2809 | Lo op through all webs and find t he given l ist. When found set the permis sions and turn on ve rsioning | ||
2810 | |||
2811 | .PARAM ETER listT itle | ||
2812 | [S tring] The name of t he list. | ||
2813 | |||
2814 | .PARAM ETER secur ityMember | ||
2815 | [[ Microsoft. SharePoint .SPMember] The secur ity group that will be granted the permi ssion | ||
2816 | |||
2817 | .PARAM ETER permi ssionMask | ||
2818 | [M icrosoft.S harePoint. SPRights] The rights and permi ssions to be granted . | ||
2819 | |||
2820 | .PARAM ETER enabl eVersionin g | ||
2821 | [s witch] The column to be displa yed in the lookup co lumn dropd own list. | ||
2822 | |||
2823 | .NOTES | ||
2824 | No t used in RAMS-2.3.0 | ||
2825 | |||
2826 | .EXAMP LE | ||
2827 | Se t-Facility ListPermis sionAndVer sioning -l istTitle " Facilities " -securit yMember "M iami Local Site Admi nistrator" -permissi onMask "Co ntribute" -enableVer sioning | ||
2828 | |||
2829 | #> | ||
2830 | |||
2831 | (Get-S iteWeb).we bs | % { | ||
2832 | $l istPerm = $_.Lists[$ listTitle] | ||
2833 | $l istPerm.Pe rmissions. Add($secur ityMember, $permissio nMask) | ||
2834 | #v ersioning | ||
2835 | if ($enableVe rsioning) { | ||
2836 | $listPer m.EnableVe rsioning = $True | ||
2837 | } | ||
2838 | $l istPerm.Up date() | ||
2839 | } | ||
2840 | } | ||
2841 | |||
2842 | function I mport-RAMS Users ($in putFilePat h) { | ||
2843 | <# | ||
2844 | |||
2845 | .SYNOP SIS | ||
2846 | Ad d and remo ve users f rom the RA MS securit y groups | ||
2847 | |||
2848 | .DESCR IPTION | ||
2849 | Us ing a csv file with 3 columns, Security Group, Per son, and A ction; upd ate the sp ecified se curity gro up. This c an be used to remove all membe rs | ||
2850 | fr om a secur ity group and then a dd new use rs using t heir full name from the Active Directory . | ||
2851 | |||
2852 | .PARAM ETER input FilePath | ||
2853 | [S tring] The filename with the p ath of the csv file. | ||
2854 | |||
2855 | .NOTES | ||
2856 | Th e file mus t have the 3 columns Security Group, Per son, and A ction. | ||
2857 | Se curity Gro up is the RAMS secur ity Group Name, e.g. New Orlea ns Adminis trative Of ficers. | ||
2858 | Pe rson is th e person's name to r emove or a dd to the group. it must be ex actly like SharePoin t is expec ting it, i ncluding a ll organiz ational su ffixes, e. g. LName, FName (CTR -ORG) or L Name, FNam e (OIFO) | ||
2859 | Th e action c olumn shou ld only ha ve the val ues Add or Remove. A dd puts th e person i n the secu rity group . Remove t akes the p erson out of the sec urity grou p. | ||
2860 | Se e GetSecur ityGroupUs ers.ps1 in ps\misc t o generate a list of the curre nt users. This can t hen be edi ted to pro duce the s ecurity gr oups neede d. | ||
2861 | |||
2862 | .EXAMP LE | ||
2863 | tr y { | ||
2864 | Add-PSSn apin Micro soft.Share Point.Powe rShell -Er rorAction SilentlyCo ntinue | ||
2865 | } catch { | ||
2866 | Write-Ho st "PSSnap in Microso ft.SharePo int.PowerS hell alrea dy loaded" -Foregrou ndColor Ye llow | ||
2867 | } | ||
2868 | |||
2869 | if ((get-mod ule | Wher e-Object({ $_.Name -e q 'RAMS_Mo dule_Util' }) ) -eq $ null) { | ||
2870 | Import-M odule D:\R AMS-2.3.0\ ps\module\ RAMS_Modul e_Util.psm 1 -Verbose | ||
2871 | } else { | ||
2872 | Remove-M odule RAMS _Module_Ut il -Verbos e | ||
2873 | Import-M odule D:\R AMS-2.3.0\ ps\module\ RAMS_Modul e_Util.psm 1 -Verbose | ||
2874 | } | ||
2875 | $i nputFilePa th = "D:\R AMS-2.3.0\ ps\misc\RA MS-itstUse rs-remove. csv" | ||
2876 | $i nputFileNa me = Split -Path $inp utFilePath -leaf | ||
2877 | $G lobal:dire toryName = $PSScript Root | ||
2878 | $G lobal:logF ileName = "$($inputF ileName).l og" | ||
2879 | Im port-RAMSU sers -inpu tFilePath $inputFile Path | ||
2880 | |||
2881 | #> | ||
2882 | |||
2883 | $webur l = Get-Si teURL | ||
2884 | $webSi te = Get-S iteWeb | ||
2885 | $userL ist = impo rt-csv -Pa th $inputF ilePath -D elimiter " ," | Selec t-Object - Property " Security G roup", Per son, Actio n | ||
2886 | |||
2887 | $userL ist | % { | ||
2888 | $g roup = $_. "Security Group" | ||
2889 | $p erson = $_ .Person | ||
2890 | $u serGroup = $webSite. SiteGroups | ? {$_.N ame -eq ($ group)} | ||
2891 | $m atchUser = $webSite. SiteUsers | ? {$_.Di splayName -eq $perso n} | ||
2892 | $a ction = $_ .Action | ||
2893 | if ($matchUse r) { | ||
2894 | $matchUs er | % { | ||
2895 | if ( $action -e q "Add") { | ||
2896 | $userGroup .AddUser($ _) | ||
2897 | write-log -message " $($matchUs er.Display Name) has been added to Securi ty Group: $($userGro up.Name)" -consoleFo reground C yan | ||
2898 | } el seif ($act ion -eq "R emove") { | ||
2899 | $userGroup .RemoveUse r($_) | ||
2900 | write-log -message " $($matchUs er.Display Name) has been remov ed to Secu rity Group : $($userG roup.Name) " -console Foreground Yellow | ||
2901 | } el se { | ||
2902 | write-log -message " $($action) is not a known acti on 'Add or Remove' f or user Gr oup: $($us erGroup.Na me) and us er $($matc hUser.Disp layName)" -consoleFo reground R ed | ||
2903 | } | ||
2904 | } | ||
2905 | } | ||
2906 | } | ||
2907 | } | ||
2908 | |||
2909 | function N ew-Meeting MinuteLook up ([Param eter (Mand atory=$Tru e)][Micros oft.ShareP oint.SPWeb ]$web, [Pa rameter (M andatory=$ True)][str ing]$commi ttee) { | ||
2910 | <# | ||
2911 | |||
2912 | .SYNOP SIS | ||
2913 | Cr eates a me eting minu te lookup column on for the ca lendar lis t. | ||
2914 | |||
2915 | .DESCR IPTION | ||
2916 | Cr eates a lo okup colum n for the committee acronym + MeetingMin uteLookup, i.e. SC1M eetingMinu teLookup. First chec ks to see if the loo kup alread y exists, if not, it is create d | ||
2917 | us ing the co mmittee ac ronym + Do cuments do cument lis t as the l ookup targ et. once c reated, th e column i s added to the calen dar list. | ||
2918 | |||
2919 | .PARAM ETER web | ||
2920 | [M icrosoft.S harePoint. SPWeb] The SPWeb of the site c ollection or facilit y subsite. | ||
2921 | |||
2922 | .PARAM ETER commi ttee | ||
2923 | [S tring] The acronym f or the com mittee | ||
2924 | |||
2925 | .EXAMP LE | ||
2926 | Ne w-MeetingM inuteLooku p -web $fa cilitySite -committe e $newComm iteeName | ||
2927 | |||
2928 | #> | ||
2929 | |||
2930 | # GET THE SITE | ||
2931 | #$web = Get-SPWe b $siteURL | ||
2932 | |||
2933 | #CREAT E SITE COL UMNS | ||
2934 | write- log -messa ge "CREATI NG $commit tee Meetin g Minute L ookup SITE COLUMNS f or site $( $web.Url)" -consoleF oreground Cyan | ||
2935 | |||
2936 | if ($c ommittee - ne "IRB") { | ||
2937 | $c alendarNam e=$committ ee + " Cal endar" | ||
2938 | } else { | ||
2939 | $c alendarNam e= "Commit tee Calend ar" | ||
2940 | } | ||
2941 | # GET THE LISTS | ||
2942 | $myLis t = $web.L ists[$cale ndarName]; | ||
2943 | |||
2944 | #Where the Sourc e List for Lookup Ex ists | ||
2945 | |||
2946 | $Paren tWebURL=$w eb.Url | ||
2947 | |||
2948 | if ($c ommittee - ne "IRB") { | ||
2949 | $P arentListN ame=$commi ttee + " D ocuments" | ||
2950 | } else { | ||
2951 | $P arentListN ame="Docum ents" | ||
2952 | } | ||
2953 | |||
2954 | $Paren tLookupCol umnName="T itle" | ||
2955 | |||
2956 | #Where the Looku p Site col umn Going to get cre ated | ||
2957 | $Child WebURL=$we b.Url | ||
2958 | |||
2959 | if ($c ommittee - ne "IRB") { | ||
2960 | $C hildLookup ColumnName = $committ ee + "Meet ingMinuteL ookup" | ||
2961 | } else { | ||
2962 | $Ch ildLookupC olumnName= "Committe eMeetingMi nuteLookup " | ||
2963 | } | ||
2964 | |||
2965 | #Get t he Parent and Child Webs and L istQ | ||
2966 | $Paren tWeb = Get -SPWeb $Pa rentWebURL | ||
2967 | $Paren tList = $P arentWeb.L ists[$Pare ntListName ] | ||
2968 | $Child Web = Get- SPWeb $Chi ldWebURL | ||
2969 | |||
2970 | write- log -messa ge "Creati ng Lookup $ChildLook upColumnNa me for $ca lendarName $($ChildW eb.Url)" - consoleFor eground Gr ay | ||
2971 | write- log -messa ge " fro m $ParentL ookupColum nName on $ ParentList Name on $( $ParentWeb .Url)" -co nsoleForeg round Gray | ||
2972 | if (!$ ChildWeb.F ields.Cont ainsField( $ChildLook upColumnNa me)) { | ||
2973 | #Ad d Lookup F ield | ||
2974 | $Ch ildLookupC olumn = $C hildWeb.Fi elds.AddLo okup($Chil dLookupCol umnName,$P arentList. id,$False) | ||
2975 | $Ch ildLookupC olumn = $C hildWeb.Fi elds[$Chil dLookupCol umnName] | ||
2976 | |||
2977 | #Se tup lookup Field pro perty | ||
2978 | $Ch ildLookupC olumn.Look upWebId = $ParentWeb .ID | ||
2979 | $Ch ildLookupC olumn.Look upField = $ParentLis t.Fields.G etFieldByI nternalNam e($ParentL ookupColum nName) | ||
2980 | |||
2981 | $Ch ildLookupC olumn.Allo wMultipleV alues=$tru e | ||
2982 | $Ch ildLookupC olumn.Grou p="RAMS IR B" | ||
2983 | if ($committe e -ne "IRB ") { | ||
2984 | $ChildLoo kupColumn. Title=$com mittee + " Meeting M inute Look up" | ||
2985 | } | ||
2986 | els e { | ||
2987 | $ChildLo okupColumn .Title="Co mmittee Me eting Minu te Lookup" | ||
2988 | } | ||
2989 | |||
2990 | $Ch ildLookupC olumn.upda te() | ||
2991 | |||
2992 | wri te-log -me ssage "$($ ChildLooku pColumn.Ti tle) Looku p field ad ded succes sfully to the web $( $web.url)" -consoleF oreground green | ||
2993 | if ($myList.F ields.Cont ainsFieldW ithStaticN ame($Child LookupColu mnName) -e q $False) { | ||
2994 | $myList.Fi elds.Add($ ChildLooku pColumn) | ||
2995 | $myList.Up date() | ||
2996 | write-log -message " $($ChildLo okupColumn .Title) Lo okup field added suc cessfully to the Cal endar List !" -consol eForegroun d green | ||
2997 | } | ||
2998 | } else { | ||
2999 | $Ch ildLookupC olumn = $C hildWeb.Fi elds.TryGe tFieldBySt aticName($ ChildLooku pColumnNam e) | ||
3000 | wri te-log -me ssage "$($ ChildLooku pColumn.Ti tle) Looku p Field Ex ists alrea dy on the web $($web .url)" -co nsoleForeg round yell ow | ||
3001 | #Ad d column t o the Cale ndar List, if missin g | ||
3002 | if ($myList.F ields.Cont ainsFieldW ithStaticN ame($Child LookupColu mnName) -e q $False) { | ||
3003 | $myList.Fi elds.Add($ ChildLooku pColumn) | ||
3004 | $myList.Up date() | ||
3005 | write-log -message " $($ChildLo okupColumn .Title) Lo okup field added suc cessfully to the Cal endar List !" -consol eForegroun d green | ||
3006 | } | ||
3007 | } | ||
3008 | } | ||
3009 | |||
3010 | function U pdate-Cale ndarView([ Parameter (Mandatory =$True)][M icrosoft.S harePoint. SPWeb]$web , [Paramet er (Mandat ory=$True) ][string]$ committee) { | ||
3011 | <# | ||
3012 | |||
3013 | .SYNOP SIS | ||
3014 | Up dates the All Events view for the calend ar. | ||
3015 | |||
3016 | .DESCR IPTION | ||
3017 | Ge ts the All Events Vi ew and add s the stan dard calen dar fields to the vi ew. | ||
3018 | |||
3019 | .PARAM ETER web | ||
3020 | [M icrosoft.S harePoint. SPWeb] The SPWeb of the site c ollection or facilit y subsite. | ||
3021 | |||
3022 | .PARAM ETER commi ttee | ||
3023 | [S tring] The acronym f or the com mittee | ||
3024 | |||
3025 | .EXAMP LE | ||
3026 | Up date-Calen darView -w eb $facili tySite -co mmittee $n ewCommitee Name | ||
3027 | |||
3028 | #> | ||
3029 | |||
3030 | $list = $web.Lis ts.TryGetL ist("$comm ittee Cale ndar") | ||
3031 | if ($l ist -ne $n ull) { | ||
3032 | #UP DATE THE V IEW | ||
3033 | wri te-log -me ssage "UPD ATING THE $committee Calendar All Events VIEW " -c onsoleFore ground Cya n | ||
3034 | $vi ew = $list .Views | ? { $_.Titl e -eq 'All Events' } ; | ||
3035 | |||
3036 | if ($view.Vie wFields.ex ists("Loca tion")){ | ||
3037 | $view.View Fields.Del ete("Locat ion"); | ||
3038 | } | ||
3039 | |||
3040 | |||
3041 | if ( $view.Vi ewFields.e xists("Eve ntDate")){ | ||
3042 | $view.View Fields.Del ete("Event Date"); | ||
3043 | } | ||
3044 | |||
3045 | if ($view.Vie wFields.ex ists("EndD ate")){ | ||
3046 | $view.View Fields.Del ete("EndDa te"); | ||
3047 | } | ||
3048 | |||
3049 | if ($view.Vie wFields.ex ists("fAll DayEvent") ){ | ||
3050 | $view.View Fields.Del ete("fAllD ayEvent"); | ||
3051 | } | ||
3052 | |||
3053 | #Cr eate custo mized view | ||
3054 | if (!$view.Vi ewFields.e xists("Eve ntDate")){ | ||
3055 | $view.View Fields.Add ("EventDat e"); | ||
3056 | } | ||
3057 | |||
3058 | if (!$view.Vi ewFields.e xists("End Date")){ | ||
3059 | $view.View Fields.Add ("EndDate" ); | ||
3060 | } | ||
3061 | |||
3062 | if (!$view.Vi ewFields.e xists("Loc ation")){ | ||
3063 | $view.View Fields.Add ("Location "); | ||
3064 | } | ||
3065 | |||
3066 | if (!$view.Vi ewFields.e xists("Eve ntAttendee s")){ | ||
3067 | $view.View Fields.Add ("EventAtt endees"); | ||
3068 | } | ||
3069 | |||
3070 | if (!$view.Vi ewFields.e xists("Com mittee Att endees")){ | ||
3071 | $view.View Fields.Add ("Committe e Attendee s"); | ||
3072 | } | ||
3073 | |||
3074 | if (!$view.Vi ewFields.e xists("Eve ntAdminist rativeItem s")){ | ||
3075 | $view.View Fields.Add ("EventAdm inistrativ eItems"); | ||
3076 | } | ||
3077 | |||
3078 | $vi ew.Default View = $tr ue | ||
3079 | $vi ew.Update( ) | ||
3080 | |||
3081 | if ($list -ne $null) { | ||
3082 | |||
3083 | $contentTy pe = "Even t" | ||
3084 | $newFieldO rder = @(" Title", | ||
3085 | "EventDa te", | ||
3086 | "EndDate ", | ||
3087 | "Locatio n", | ||
3088 | "fAllDay Event", | ||
3089 | "fRecurr ence", | ||
3090 | "EventCo mmitteeAtt endees", | ||
3091 | "EventAt tendees", | ||
3092 | "Partici pantsPicke r", | ||
3093 | "EventAd ministrati veItems", | ||
3094 | "TaxKeyw ord", | ||
3095 | "Submitt edApplicat ionLookup" , | ||
3096 | "$($comm ittee)Meet ingMinuteL ookup", | ||
3097 | "Deliber ation", | ||
3098 | "Decisio n" | ||
3099 | ) | ||
3100 | if ($list. Fields.Con tainsField ("Descript ion")) { | ||
3101 | $ct = $ list.Conte ntTypes[$c ontentType ] | ||
3102 | $ct.Fie ldLinks["D escription "].Hidden = $True | ||
3103 | $ct.Fie ldLinks.Re order($new FieldOrder ) | ||
3104 | $ct.Upd ate() | ||
3105 | $list.U pdate() | ||
3106 | } | ||
3107 | |||
3108 | if ($list. Fields.Con tainsField ("Category ")) { | ||
3109 | $catego ryfield=$l ist.Fields ["Category "] | ||
3110 | $catego ryfield.Sh owInNewFor m=$false | ||
3111 | $catego ryfield.Sh owInEditFo rm=$false | ||
3112 | $catego ryfield.Up date($true ) | ||
3113 | $list.U pdate() | ||
3114 | } | ||
3115 | |||
3116 | if ($list. Fields.Con tainsField ("Applicat ionsLookup ")) { | ||
3117 | $applic ationsFiel d=$list.Fi elds["Appl icationsLo okup"] | ||
3118 | $applic ationsFiel d.ShowInNe wForm=$fal se | ||
3119 | $applic ationsFiel d.ShowInEd itForm=$fa lse | ||
3120 | $applic ationsFiel d.Update($ true) | ||
3121 | $list.U pdate() | ||
3122 | } | ||
3123 | |||
3124 | if ($list. Fields.Con tainsField ("RDCMinut eLookup")) { | ||
3125 | $approv edRDCAppli cationLook up=$list.F ields["RDC MinuteLook up"] | ||
3126 | $approv edRDCAppli cationLook up.ShowInN ewForm=$fa lse | ||
3127 | $approv edRDCAppli cationLook up.ShowInE ditForm=$f alse | ||
3128 | $approv edRDCAppli cationLook up.Update( $true) | ||
3129 | $list.U pdate() | ||
3130 | } | ||
3131 | |||
3132 | if ($list. Fields.Con tainsField ("Approved Applicati on Lookup" )) { | ||
3133 | $applic ationsFiel d=$list.Fi elds["Appr oved Appli cation Loo kup"] | ||
3134 | $applic ationsFiel d.ShowInNe wForm=$fal se | ||
3135 | $applic ationsFiel d.ShowInEd itForm=$fa lse | ||
3136 | $applic ationsFiel d.Update($ true) | ||
3137 | $list.U pdate() | ||
3138 | } | ||
3139 | |||
3140 | if ($list. Fields.Con tainsField ("Attendee s")) { | ||
3141 | $applic ationsFiel d=$list.Fi elds["Atte ndees"] | ||
3142 | $applic ationsFiel d.ShowInNe wForm=$fal se | ||
3143 | $applic ationsFiel d.ShowInEd itForm=$fa lse | ||
3144 | $applic ationsFiel d.Update($ true) | ||
3145 | $list.U pdate() | ||
3146 | } | ||
3147 | |||
3148 | if ($list. Fields.Con tainsField ("Administ rative Ite ms")) { | ||
3149 | $applic ationsFiel d=$list.Fi elds["Admi nistrative Items"] | ||
3150 | $applic ationsFiel d.ShowInNe wForm=$tru e | ||
3151 | $applic ationsFiel d.ShowInEd itForm=$tr ue | ||
3152 | $applic ationsFiel d.Update($ true) | ||
3153 | $list.U pdate() | ||
3154 | } | ||
3155 | } | ||
3156 | } | ||
3157 | } | ||
3158 | |||
3159 | function N ew-SPList ([Paramete r (Mandato ry=$True)] [Microsoft .SharePoin t.SPWeb]$w eb, [Param eter (Mand atory=$Tru e)][string ]$newCommi teeName,[P arameter ( Mandatory= $True)][Va lidateSet( "Documents ", "Calend ar", "Form Library") ][string]$ templateNa me ) { | ||
3160 | <# | ||
3161 | |||
3162 | .SYNOP SIS | ||
3163 | Cr eates a ne w SharePoi nt List. | ||
3164 | |||
3165 | .DESCR IPTION | ||
3166 | Cr eate a new sharepoin t list of type docum ents, cale ndar, or F orm Librar y. First c hecks to s ee if the list is | ||
3167 | pr esent then names it by the com mittee nam e + the te mplate nam e. finally it turns on version ing. | ||
3168 | |||
3169 | .PARAM ETER web | ||
3170 | [M icrosoft.S harePoint. SPWeb] The SPWeb of the site c ollection or facilit y subsite. | ||
3171 | |||
3172 | .PARAM ETER newCo mmiteeName | ||
3173 | [S tring] The acronym f or the com mittee | ||
3174 | |||
3175 | .PARAM ETER templ ateName | ||
3176 | [S tring] The type of l ist to cre ate. Can o nly be of type "Docu ments", "C alendar", or "Form L ibrary". | ||
3177 | |||
3178 | .EXAMP LE | ||
3179 | $n ewDoc = Ne w-SPList - web $facil itySite -n ewCommitee Name $newC ommiteeNam e -templat e Document s -Verbose | ||
3180 | |||
3181 | .EXAMP LE | ||
3182 | $n ewCalendar = New-SPL ist -web $ facilitySi te -newCom miteeName $newCommit eeName -te mplate Cal endar -Ver boseUpdate -CalendarV iew -web $ facilitySi te -commit tee $newCo mmiteeName | ||
3183 | |||
3184 | #> | ||
3185 | |||
3186 | $websi te = (Get- SiteWeb) | ||
3187 | |||
3188 | if($te mplateName -eq "Docu ments") { | ||
3189 | $t emplate = $website.L istTemplat es["Docume nt Library "] | ||
3190 | } else { | ||
3191 | $t emplate = $website.L istTemplat es["$templ ateName"] | ||
3192 | } | ||
3193 | |||
3194 | $facil itySite = $web | ||
3195 | |||
3196 | #add n ew list | ||
3197 | if(($f acilitySit e.Lists.Tr yGetList(" $($newComm iteeName)$ templateNa me")) -eq $Null) { | ||
3198 | $f acilitySit e.Lists.Ad d("$($newC ommiteeNam e)$templat eName","$( $newCommit eeName) $t emplateNam e",$templa te) | ||
3199 | } | ||
3200 | $newSP List = $fa cilitySite .Lists.Try GetList("$ ($newCommi teeName)$t emplateNam e") | ||
3201 | |||
3202 | #chang e title | ||
3203 | $newSP List.Title ="$($newCo mmiteeName ) $templat eName"; | ||
3204 | |||
3205 | #enabl e versioni ng | ||
3206 | $newSP List.Enabl eVersionin g = $True; | ||
3207 | |||
3208 | #updat e calendar | ||
3209 | $newSP List.Updat e() | ||
3210 | write- log -messa ge "$($new SPList.Tit le) added to site $( $web.Url)" -consoleF oreground Green | ||
3211 | #retur n | ||
3212 | return $newSPLis t | ||
3213 | } | ||
3214 | |||
3215 | function N ew-SSISDB ($dbServer ,$ProjectN ame, $Proj ectFilePat h) { | ||
3216 | <# | ||
3217 | |||
3218 | .SYNOP SIS | ||
3219 | In stall and update the SSIS Data base with the releas e componen ts. | ||
3220 | |||
3221 | .DESCR IPTION | ||
3222 | Bu ilds a scr ipt and ex ecutes on the SSISDB Server. T he script connects t o the SSIS instance, creates t he catalog , | ||
3223 | cr eates a pr oject fold er, and th en deploys the proje ct ispac f ile. | ||
3224 | |||
3225 | .PARAM ETER dbSer ver | ||
3226 | [S tring] The name of t he SSIS se rver. | ||
3227 | |||
3228 | .PARAM ETER Proje ctName | ||
3229 | [S tring] Nam e of the p roject wit hout exten sions. An ispac file will have 3 parts, the projec t name + _ + Environ ment + | ||
3230 | .i spac, e.g EmailNotif ication_TE ST.ispac o r EmailNot ification_ PROD.ispac . This par ameter is only the f irst part of the | ||
3231 | fi le name. | ||
3232 | |||
3233 | .PARAM ETER Proje ctFilePath | ||
3234 | [S tring] The location of the isp ac file. A n ispac fi le will ha ve 3 parts , the proj ect name + _ + Envir onment + | ||
3235 | .i spac, e.g EmailNotif ication_TE ST.ispac o r EmailNot ification_ PROD.ispac . This par ameter is the full n ame of the file with | ||
3236 | th e full pat h on the d estination server. | ||
3237 | |||
3238 | .EXAMP LE | ||
3239 | $G lobal:file LocationIS AC = "D:\$ RAMSVersio n\sql" | ||
3240 | Co py-Item "$ Global:fil eLocationI SAC\EmailN otificatio n_$($envNa me).ispac" -Destinat ion "\\$($ Global:hos tInfo.ssis )\D$\" -Ve rbose | ||
3241 | Ne w-SSISDB - dbServer ( $Global:ho stInfo.ssi s) -Projec tName "Ema ilNotifica tion" -Pro jectFilePa th "D:\Ema ilNotifica tion_$($en vName).isp ac" | ||
3242 | |||
3243 | #> | ||
3244 | $sbSSI SServer = $Global:ho stInfo.ssi s | ||
3245 | $sbDBS erver = $G lobal:host Info.sql | ||
3246 | $sbCon tentDBName = Get-SPC ontentData base -Site (Get-Site URL) | ||
3247 | $sbRAM SDBName = "RAMS" | ||
3248 | $scrip tBlock = { | ||
3249 | $s bSSISServe r = $args[ 0] | ||
3250 | $s bDBServer = $args[1] | ||
3251 | $s bContentDB Name = $ar gs[2] | ||
3252 | $s bRAMSDBNam e = $args[ 3] | ||
3253 | |||
3254 | fu nction Cre ate-SSISAg entJob { | ||
3255 | <# | ||
3256 | |||
3257 | .SYNOPSI S | ||
3258 | Crea te SSIS ag ent jobs | ||
3259 | |||
3260 | .DESCRIP TION | ||
3261 | |||
3262 | |||
3263 | .PARAMET ER webServ iceUrl | ||
3264 | [str ing] The S SIS web se rvices URL . | ||
3265 | |||
3266 | .PARAMET ER reportF older | ||
3267 | [str ing] The n ame of the folder on the SSRS server whe re the rep orts will be importe d. "RAMS R eports" is the | ||
3268 | defa ult. | ||
3269 | |||
3270 | .PARAMET ER AgentJo bName | ||
3271 | [str ing] The n ame of the folder on the SSRS server whe re the dat a sources will be im ported. "D ata Source s" is the | ||
3272 | defa ult. | ||
3273 | |||
3274 | .PARAMET ER dtsxPac kage | ||
3275 | [str ing] The b ase direct ory of the reports d irectory i n the depl oyment pac kage. Buil t using th e RAMS rel ease | ||
3276 | numb er, e.g. R AMS-2.3.0, and addin g the repo rts direct ory. For e xample, D: \RAMS-2.3. 0\Reports. | ||
3277 | |||
3278 | .NOTES | ||
3279 | Modi fied from http://mic rosoft-ssi s.blogspot .com/2016/ 10/using-p owershell- to-create- sql-agent. html | ||
3280 | |||
3281 | .EXAMPLE | ||
3282 | Crea te-SSISAge ntJob -ssi sServer $s bSSISServe r -dbServe r $sbDBSer ver -repor tFolder "R AMS" -dtsx Package "A nnualRevie wNotificat ion.dtsx" -projectNa me "EmailN otificatio n" -conten tDBName $s bContentDB Name -rams DBName $sb RAMSDBName -jobStart Time (New- Timespan - hours 23 - minutes 00 ) | ||
3283 | |||
3284 | .EXAMPLE | ||
3285 | Crea te-SSISAge ntJob -ssi sServer $s bSSISServe r -dbServe r $sbDBSer ver -repor tFolder "R AMS" -dtsx Package "T rainingExp irationNot ification. dtsx" -pro jectName " EmailNotif ication" - contentDBN ame $sbCon tentDBName -ramsDBNa me $sbRAMS DBName -jo bStartTime (New-Time span -hour s 23 -minu tes 30) | ||
3286 | #> | ||
3287 | Param( | ||
3288 | [str ing]$ssisS erver, | ||
3289 | [str ing]$dbSer ver, | ||
3290 | [str ing]$repor tFolder = "RAMS", | ||
3291 | [str ing]$dtsxP ackage, | ||
3292 | [str ing]$jobNa me, | ||
3293 | [str ing]$proje ctName, | ||
3294 | [str ing]$conte ntDBName, | ||
3295 | [str ing]$ramsD BName, | ||
3296 | [Tim espan]$job StartTime | ||
3297 | ) | ||
3298 | #PowerSh ell SSIS J obStep | ||
3299 | ######## ########## ########## #### | ||
3300 | ######## ## PARAMET ERS ###### #### | ||
3301 | ######## ########## ########## #### | ||
3302 | # Destin ation | ||
3303 | #$SsisSe rver = $we bServiceUr l | ||
3304 | #$report Folder = $ reportFold er | ||
3305 | #$Projec tName = $P rojectName | ||
3306 | |||
3307 | # Job | ||
3308 | #$JobNam e = $agent JobName | ||
3309 | #$dtsxPa ckage = $d tsxPackage | ||
3310 | #$JobSta rtTime = N ew-TimeSpa n -hours 2 3 -minutes 00 | ||
3311 | |||
3312 | #clear | ||
3313 | write-ho st "====== ========== ========== ========== ========== ========== ==" -Foreg roundColor white | ||
3314 | write-ho st "== Us ed paramet ers ==" -Foreg roundColor white | ||
3315 | write-ho st "====== ========== ========== ========== ========== ========== ==" -Foreg roundColor white | ||
3316 | write-ho st "SSIS S erver : $ SsisServer " -Foregr oundColor white | ||
3317 | write-ho st "DB Ser ver : $ dbServer" -Foregroun dColor whi te | ||
3318 | write-ho st "report Folder : $ reportFold er" -Foreg roundColor white | ||
3319 | write-ho st "Projec tName : $ projectNam e" -Foregr oundColor white | ||
3320 | write-ho st "Job na me : $ jobName" - Foreground Color whit e | ||
3321 | write-ho st "dtsxPa ckage : $ dtsxPackag e" -Foregr oundColor white | ||
3322 | write-ho st "conten tDBName : $ contentDBN ame" -Fore groundColo r white | ||
3323 | write-ho st "ramsDB Name : $ ramsDBName " -Foregro undColor w hite | ||
3324 | write-ho st "Schedu leTime : $ JobStartTi me" -Foreg roundColor white | ||
3325 | write-ho st "====== ========== ========== ========== ========== ========== ==" -Foreg roundColor white | ||
3326 | write-ho st " " -Fo regroundCo lor white | ||
3327 | |||
3328 | |||
3329 | # Refere nce SMO as sembly and connect t o the SQL Sever Inst ance | ||
3330 | # Check the number in the pa th which i s differen t for each version | ||
3331 | Add-Type -Path 'C: \Program F iles (x86) \Microsoft SQL Serve r\100\SDK\ Assemblies \Microsoft .SqlServer .Smo.dll' | ||
3332 | $SQLSvr = New-Obje ct -TypeNa me Micros oft.SQLSer ver.Manage ment.Smo.S erver($Ssi sServer) | ||
3333 | |||
3334 | # Check if job alr eady exist s. Then fa il, rename or drop | ||
3335 | $SQLJob = $SQLSvr. JobServer. Jobs[$JobN ame] | ||
3336 | if ($SQL Job){ | ||
3337 | # Use one of the se 3 optio ns to hand le existin g jobs | ||
3338 | |||
3339 | # Fail : | ||
3340 | #Throw [System.E xception] "Job with name '$Job Name' alre ady exists ." | ||
3341 | |||
3342 | # Rena me: | ||
3343 | write- host "Job with name '$JobName ' found, r enaming an d disablin g it" -For egroundCol or white | ||
3344 | $SQLJo b.Rename($ SQLJob.Nam e +"_OLD_" + (Get-Da te -f MM-d d-yyyy_HH_ mm_ss)) | ||
3345 | $SQLJo b.IsEnable d = $false | ||
3346 | $SQLJo b.Alter() | ||
3347 | |||
3348 | # Drop : | ||
3349 | #write -host "Jo b with nam e $JobName found, re moving it" | ||
3350 | #$SQLJ ob.Drop() | ||
3351 | } | ||
3352 | |||
3353 | |||
3354 | #Create new (empty ) job | ||
3355 | $SQLJob = New-Obje ct -TypeNa me Microso ft.SqlServ er.Managem ent.SMO.Ag ent.Job -a rgumentlis t $SQLSvr. JobServer, $JobName | ||
3356 | $SQLJob. OwnerLogin Name = "SA " | ||
3357 | $SQLJob. Create() | ||
3358 | write-ho st "Job ' $JobName' created" - Foreground Color Gree n | ||
3359 | |||
3360 | |||
3361 | # Comman d of jobst ep | ||
3362 | # This s tring is c opied from T-SQL, by scripting a job(ste p) in SSMS | ||
3363 | # Then r eplace the hardcode strings wi th [NAME] to replace them with variables | ||
3364 | $Command = @' | ||
3365 | /ISSERVE R "\"\SSIS DB\[FOLDER ]\[PROJECT ]\[PACKAGE ]\"" /SERV ER [SSISSE RVER] /Par "\"$Proje ct::Config DB_Connect ionString\ "";"\"Data Source=[D BSERVER];I nitial Cat alog=[CNTD B];Provide r=SQLNCLI1 1.1;Integr ated Secur ity=SSPI;A uto Transl ate=False; \"" /Par " \"$Project ::RAMS_Con nectionStr ing\"";"\" Data Sourc e=[DBSERVE R];Initial Catalog=R AMS;Provid er=SQLNCLI 11.1;Integ rated Secu rity=SSPI; Auto Trans late=False ;\"" /Par "\"$Server Option::LO GGING_LEVE L(Int16)\" ";1 /Par " \"$ServerO ption::SYN CHRONIZED( Boolean)\" ";True /CA LLERINFO S QLAGENT /R EPORTING E | ||
3366 | '@ | ||
3367 | |||
3368 | # FOLDER PROJEC T PACKAG E SSIS SERVER DB SERVER SP CNT DB DB SERV ER R AMS DB | ||
3369 | # |------ -| |------ -| |------ -| |----- -----| | --------| |--- --| |------ --| |--| | ||
3370 | #/ISSERV ER "\"\SSI SDB\[FOLDE R]\[PROJEC T]\[PACKAG E]\"" /SER VER [SSISS ERVER] /Pa r "\"$Proj ect::Confi gDB_Connec tionString \"";"\"Dat a Source=[ DBSERVER]; Initial Ca talog=[CNT DB];Provid er=SQLNCLI 11.1;Integ rated Secu rity=SSPI; Auto Trans late=False ;\"" /Par "\"$Projec t::RAMS_Co nnectionSt ring\"";"\ "Data Sour ce=[DBSERV ER];Initia l Catalog= RAMS;Provi der=SQLNCL I11.1;Inte grated Sec urity=SSPI ;Auto Tran slate=Fals e;\"" /Par "\"$Serve rOption::L OGGING_LEV EL(Int16)\ "";1 /Par "\"$Server Option::SY NCHRONIZED (Boolean)\ "";True /C ALLERINFO SQLAGENT / REPORTING E | ||
3371 | #/ISSERV ER "\"\SSI SDB\[FOLDE R]\[PROJEC T]\[PACKAG E]\"" /SER VER [SSISS ERVER] /Pa r "\"$Proj ect::Confi gDB_Connec tionString \"";"\"Dat a Source=[ DBSERVER]; Initial Ca talog=[CNT DB];Provid er=SQLNCLI 11.1;Integ rated Secu rity=SSPI; Auto Trans late=False ;\"" /Par "\"$Projec t::RAMS_Co nnectionSt ring\"";"\ "Data Sour ce=[DBSERV ER];Initia l Catalog= RAMS;Provi der=SQLNCL I11.1;Inte grated Sec urity=SSPI ;Auto Tran slate=Fals e;\"" /Par "\"$Serve rOption::L OGGING_LEV EL(Int16)\ "";1 /Par "\"$Server Option::SY NCHRONIZED (Boolean)\ "";True /C ALLERINFO SQLAGENT / REPORTING E | ||
3372 | #/ISSERVER "\"\SSISD B\RAMS\Ema ilNotifica tion\Train ingExpirat ionNotific ation.dtsx \"" /SERVE R DNS SQLRAM906 /Par "\"$P roject::Co nfigDB_Con nectionStr ing\"";"\" Data Sourc e= DN S
|
||
3373 | #/ISSERVER "\"\SSISD B\RAMS\Ema ilNotifica tion\Annua lReviewNot ification. dtsx\"" /S ERVER DNS SQLRAM906 /Par "\"$P roject::Co nfigDB_Con nectionStr ing\"";"\" Data Sourc e= DN S
|
||
3374 | $Command = $Comman d.Replace( "[FOLDER]" , $reportF older) | ||
3375 | $Command = $Comman d.Replace( "[PROJECT] ", $Projec tName) | ||
3376 | $Command = $Comman d.Replace( "[PACKAGE] ", $dtsxPa ckage) | ||
3377 | $Command = $Comman d.Replace( "[SSISSERV ER]", $Ssi sServer) | ||
3378 | $Command = $Comman d.Replace( "[DBSERVER ]", $dbSer ver) | ||
3379 | $Command = $Comman d.Replace( "[CNTDB]", $contentD BName) | ||
3380 | $Command = $Comman d.Replace( "[RAMSDB]" , $ramsDBN ame) | ||
3381 | $Command = $Comman d.Replace( "[DBSERVER ]", $SsisS erver) | ||
3382 | |||
3383 | |||
3384 | # Create new SSIS job step w ith comman d from pre vious bloc k | ||
3385 | $SQLJobS tep = New- Object -Ty peName Mic rosoft.Sql Server.Man agement.SM O.Agent.Jo bStep -arg umentlist $SQLJob, " $ProjectNa me - $dtsx Package" | ||
3386 | $SQLJobS tep.OnSucc essAction = [Microso ft.SqlServ er.Managem ent.Smo.Ag ent.StepCo mpletionAc tion]::Qui tWithSucce ss | ||
3387 | $SQLJobS tep.OnFail Action = [ Microsoft. SqlServer. Management .Smo.Agent .StepCompl etionActio n]::QuitWi thFailure | ||
3388 | $SQLJobS tep.SubSys tem = "SSI S" | ||
3389 | $SQLJobS tep.Databa seName = $ SsisServer | ||
3390 | $SQLJobS tep.Comman d = $Comma nd | ||
3391 | $SQLJobS tep.Create () | ||
3392 | write-ho st "Jobst ep $SQLJob Step creat ed" -Foreg roundColor green | ||
3393 | |||
3394 | |||
3395 | # Create a daily s chedule | ||
3396 | $SQLJobS chedule = New-Object -TypeName Microsoft .SqlServer .Managemen t.Smo.Agen t.JobSched ule -Argum entList $S QLJob, "Da ily $JobSt artTime" | ||
3397 | $SQLJobS chedule.Is Enabled = $true | ||
3398 | $SQLJobS chedule.Fr equencyTyp es = [Micr osoft.SqlS erver.Mana gement.SMO .Agent.Fre quencyType s]::Daily | ||
3399 | $SQLJobS chedule.Fr equencyInt erval = 1 # Recurs E very Day | ||
3400 | $SQLJobS chedule.Ac tiveStartD ate = Get- Date | ||
3401 | $SQLJobS chedule.Ac tiveStartT imeofDay = $JobStart Time | ||
3402 | $SQLJobS chedule.Cr eate() | ||
3403 | write-ho st "Jobsc hedule $SQ LJobSchedu le created " -Foregro undColor g reen | ||
3404 | |||
3405 | |||
3406 | # Apply to target server whi ch can onl y be done after the job is cre ated | ||
3407 | $SQLJob. ApplyToTar getServer( "(local)") | ||
3408 | $SQLJob. Alter() | ||
3409 | write-ho st "Job ' $JobName' saved" -Fo regroundCo lor green | ||
3410 | } | ||
3411 | |||
3412 | |||
3413 | # Load the I ntegration Services A ssembly | ||
3414 | [R eflection. Assembly]: :LoadWithP artialName ("Microsof t.SqlServe r.Manageme nt.Integra tionServic es") | ||
3415 | # Store the Integratio nServices Assembly n amespace t o avoid ty ping it ev ery time | ||
3416 | $I SNamespace = "Micros oft.SqlSer ver.Manage ment.Integ rationServ ices" | ||
3417 | |||
3418 | wr ite-host "Connectin g to serve r ..." -F oregroundC olor white | ||
3419 | |||
3420 | # Create a c onnection to the ser ver | ||
3421 | $s qlConnecti onString = "Data Sou rce=$Using :dbServer; Initial Ca talog=mast er;Integra ted Securi ty=SSPI;" | ||
3422 | $s qlConnecti on = New-O bject Syst em.Data.Sq lClient.Sq lConnectio n $sqlConn ectionStri ng | ||
3423 | |||
3424 | # Create the Integrati on Service s object | ||
3425 | $i ntegration Services = New-Objec t $ISNames pace".Inte grationSer vices" $sq lConnectio n | ||
3426 | |||
3427 | #e nable CLR | ||
3428 | $q uery = "ex ec sp_conf igure 'clr enabled', 1 | ||
3429 | reconfig ure | ||
3430 | go | ||
3431 | " | ||
3432 | In voke-Sqlcm d -ServerI nstance $U sing:dbSer ver -Query $query -V erbose | ||
3433 | |||
3434 | if ($integra tionServic es.Catalog s.Count -g t 0) { | ||
3435 | $catalog = $integr ationServi ces.Catalo gs["SSISDB "] | ||
3436 | $folder = $catalog .Folders[" RAMS"] | ||
3437 | if(!$fol der) { | ||
3438 | $fol der = New- Object $IS Namespace" .CatalogFo lder" ($ca talog, "RA MS","RAMS SSIS Folde r") | ||
3439 | $fol der.Create () | ||
3440 | } | ||
3441 | } else { | ||
3442 | # Provis ion a new SSIS Catal og | ||
3443 | $catalog = New-Obj ect $ISNam espace".Ca talog" ($i ntegration Services, "SSISDB", "'7G>n3Rr= 4wV") | ||
3444 | $catalog .Create() | ||
3445 | |||
3446 | # Create the targe t folder | ||
3447 | $folder = New-Obje ct $ISName space".Cat alogFolder " ($catalo g, "RAMS", "RAMS SSIS Folder") | ||
3448 | $folder. Create() | ||
3449 | } | ||
3450 | |||
3451 | # Read the p roject fil e and depl oy it | ||
3452 | [b yte[]] $pr ojectFile = [System. IO.File]:: ReadAllByt es($Using: ProjectFil ePath) | ||
3453 | $f older.Depl oyProject( $Using:Pro jectName, $projectFi le) | ||
3454 | |||
3455 | # Create the jobs | ||
3456 | |||
3457 | |||
3458 | Cr eate-SSISA gentJob -s sisServer $sbSSISSer ver -dbSer ver $sbDBS erver -rep ortFolder "RAMS" -dt sxPackage "AnnualRev iewNotific ation.dtsx " -jobName "Annual R eview Noti fication" -projectNa me "EmailN otificatio n" -conten tDBName $s bContentDB Name -rams DBName $sb RAMSDBName -jobStart Time (New- Timespan - hours 23 - minutes 00 ) | ||
3459 | Cr eate-SSISA gentJob -s sisServer $sbSSISSer ver -dbSer ver $sbDBS erver -rep ortFolder "RAMS" -dt sxPackage "TrainingE xpirationN otificatio n.dtsx" -j obName "Tr aining Exp iration No tification " -project Name "Emai lNotificat ion" -cont entDBName $sbContent DBName -ra msDBName $ sbRAMSDBNa me -jobSta rtTime (Ne w-Timespan -hours 23 -minutes 30) | ||
3460 | wr ite-host "Done." -F oregroundC olor Green | ||
3461 | } | ||
3462 | |||
3463 | write- log -messa ge "SSIS I nstall Res ults Start : NOTE - Not all of the infor mation bet ween here and the SS IS Install Results E nd is writ ten to the log." -co nsoleForeg round Mage nta | ||
3464 | $job = Invoke-Co mmand -Com puterName $dbServer -ScriptBlo ck $script Block -Arg umentList $sbSSISSer ver, $sbDB Server, $s bContentDB Name.Name, $sbRAMSDB Name -AsJo b -Verbose | ||
3465 | Wait-j ob $job | ||
3466 | $resul ts = Recei ve-Job $jo b | ||
3467 | $resul ts | selec t PSComput erName, Cr eatedTime, ObjectNam e, Status, Parent, C ompleted | Write-Lo g | ||
3468 | write- log -messa ge "SSIS I nstall Res ults End: NOTE - No t all of t he informa tion betwe en here an d the SSIS Install R esults Sta rt is writ ten to the log." -co nsoleForeg round Mage nta | ||
3469 | } | ||
3470 | |||
3471 | function I nstall-SSI SAdapter ( $dbServer) { | ||
3472 | <# | ||
3473 | |||
3474 | .SYNOP SIS | ||
3475 | In stall the SharePoint List Adap ter on the SSIS Serv er. | ||
3476 | |||
3477 | .DESCR IPTION | ||
3478 | Re motely ins tall the S harePoint List Adapt er on the SSIS Serve r. This sc ript assum es success . | ||
3479 | |||
3480 | .PARAM ETER dbSer ver | ||
3481 | [S tring] The name of t he SSIS se rver. | ||
3482 | |||
3483 | .EXAMP LE | ||
3484 | In stall-SSIS Adapter -d bServer ($ Global:hos tInfo.ssis ) | ||
3485 | |||
3486 | #> | ||
3487 | |||
3488 | Copy-I tem .\Shar ePointList AdapterSet up_x64.msi -Destinat ion \\$dbS erver\D$\ -Verbose | ||
3489 | $SPAda pterInstal l={ | ||
3490 | St art-Proces s msiexec. exe -Wait -ArgumentL ist '/I D: \SharePoin tListAdapt erSetup_x6 4.msi /qui et' -PassT hru | ||
3491 | } | ||
3492 | Invoke -Command - ComputerNa me $dbServ er -Script Block $SPA dapterInst all -Verbo se | write -log | ||
3493 | Start- Sleep -Sec onds 60 | ||
3494 | write- log -messa ge "ShareP oint SSIS Adapter is now insta lled on $d bServer" - consoleFor eground Gr een | ||
3495 | } | ||
3496 | |||
3497 | function R un-Script ([string] $step, [st ring]$scri ptName) { | ||
3498 | <# | ||
3499 | |||
3500 | .SYNOP SIS | ||
3501 | Ex ecutes the ScriptNam e | ||
3502 | |||
3503 | .DESCR IPTION | ||
3504 | Ca lculates t he percent complete to show pr ogress. Te lls the us ers what i s happenin g, checks to | ||
3505 | se e if the r equested s cript name is presen t, and if so, execut es it. | ||
3506 | |||
3507 | .PARAM ETER step | ||
3508 | [S tring] The text to d isplay the user spec ified step number. S uggest num bering by 10s so ste ps | ||
3509 | ca n easily b e inserted without h aving to r enumber to o often. | ||
3510 | |||
3511 | .PARAM ETER scrip tName | ||
3512 | [S tring] The filename of the pow ershell sc ript to ex ecute. Thi s will use the fileL ocationPS to | ||
3513 | lo ok for the script. | ||
3514 | |||
3515 | .NOTES | ||
3516 | TO DO: Need t o figure o ut how to pass in ad ditional p arameters and pass t hem thru t o the | ||
3517 | de signated s cript. For now, this function cannot run scripts t hat requir e addition al paramet ers. | ||
3518 | |||
3519 | .EXAMP LE | ||
3520 | Ru n-Script 0 10 UpdateE nvironment List.ps1 | ||
3521 | |||
3522 | #> | ||
3523 | |||
3524 | $Globa l:perCompl ete = $Glo bal:perCom plete + $G lobal:coun t | ||
3525 | Write- Progress - Activity " RAMS 2.3 D eployment - Step: $s tep [$scri ptInc]" -P ercentComp lete $Glob al:perComp lete | ||
3526 | $scrip tInc = Joi n-Path $Gl obal:fileL ocationPS $scriptNam e | ||
3527 | write- log -messa ge "$scrip tInc" -con soleForegr ound Magen ta | ||
3528 | if(Tes t-Path -Pa th $script Inc) { | ||
3529 | . $scriptInc | ||
3530 | } else { | ||
3531 | wr ite-log -m essage "Fi le Not Fou nd: $scrip tInc" -con soleForegr ound Red | ||
3532 | } | ||
3533 | } | ||
3534 | |||
3535 | function W rite-Log { | ||
3536 | <# | ||
3537 | .SYNOP SIS | ||
3538 | Wr ites loggi ng informa tion to sc reen and l og file si multaneous ly. | ||
3539 | |||
3540 | .DESCR IPTION | ||
3541 | Wr ites loggi ng informa tion to sc reen and l og file si multaneous ly. Suppor ts multipl e log leve ls. | ||
3542 | |||
3543 | .PARAM ETER Messa ge - The M essage to be logged. | ||
3544 | .PARAM ETER Level - The typ e of Messa ge to be l ogged, ERR OR, WARN, INFO (defa ult). | ||
3545 | .PARAM ETER NoCon soleOut - Specifies to not dis play the M essage to the consol e. | ||
3546 | .PARAM ETER Conso leForegrou nd - Speci fies what color the text shoul d be be di splayed on the conso le. Ignore d when swi tch 'NoCon soleOut' i s specifie d. | ||
3547 | .PARAM ETER Inden t - The nu mber of sp aces to in dent the l ine in the log file. | ||
3548 | .PARAM ETER Path - The log file path. | ||
3549 | .PARAM ETER Clobb er - Exist ing log fi le is dele ted when t his is spe cified. | ||
3550 | .PARAM ETER Event LogName - The name o f the syst em event l og, e.g. ' Applicatio n'. | ||
3551 | .PARAM ETER Event Source - T he name to appear as the sourc e attribut e for the system eve nt log ent ry. This i s ignored unless 'Ev entLogName ' is speci fied. | ||
3552 | .PARAM ETER Event ID - The ID to appe ar as the event ID a ttribute f or the sys tem event log entry. This is i gnored unl ess 'Event LogName' i s specifie d. | ||
3553 | .PARAM ETER LogEn coding The text enco ding for t he log fil e. Default is ASCII. | ||
3554 | |||
3555 | .EXAMP LE | ||
3556 | PS C:\> Writ e-Log -Mes sage "It's all good! " -Path C: \MyLog.log -Clobber -EventLogN ame 'Appli cation' | ||
3557 | PS C:\> Writ e-Log -Mes sage "Oops , not so g ood!" -Lev el Warn -E ventID 3 - Indent 2 - EventLogNa me 'Applic ation' -Ev entSource "My Script " .INPUTS System.Str ing | ||
3558 | |||
3559 | .OUTPU TS | ||
3560 | No output | ||
3561 | |||
3562 | .NOTES | ||
3563 | fr om https:/ /gallery.t echnet.mic rosoft.com /scriptcen ter/Powers hell-funct ion-to-5fd e9091 | ||
3564 | #A uthor - Vi kram Bedi | ||
3565 | #v ikram.bedi .it@gmail. com | ||
3566 | #P owershell v2.0 #v1.0 Initial S cript | ||
3567 | #> | ||
3568 | |||
3569 | #regio n Paramete rs | ||
3570 | [c mdletbindi ng()] | ||
3571 | Pa ram( | ||
3572 | [Paramet er(ValueFr omPipeline =$True,Man datory=$Tr ue)] [Vali dateNotNul lOrEmpty() ] | ||
3573 | [string] $Message, | ||
3574 | [Paramet er()] [Val idateSet(" Error", "W arn", "Inf o")] | ||
3575 | [string] $Level = "Info", | ||
3576 | [Paramet er()] | ||
3577 | [Switch] $NoConsol eOut, | ||
3578 | [Paramet er()] | ||
3579 | [String] $ConsoleF oreground = 'White', | ||
3580 | [Paramet er()] [Val idateRange (1,30)] | ||
3581 | [Int16] $Indent = 0, | ||
3582 | [Paramet er()] | ||
3583 | [IO.File Info] $Pat h = "$Glob al:diretor yName\$Glo bal:logFil eName", | ||
3584 | [Paramet er()] | ||
3585 | [Switch] $Clobber, | ||
3586 | [Paramet er()] | ||
3587 | [String] $EventLog Name, | ||
3588 | [Paramet er()] | ||
3589 | [String] $EventSou rce, | ||
3590 | [Paramet er()] | ||
3591 | [Int32] $EventID = 1, | ||
3592 | [Paramet er()] | ||
3593 | [String] $LogEncod ing = "ASC II" | ||
3594 | ) #end Param eters | ||
3595 | #endre gion | ||
3596 | |||
3597 | Begin {} | ||
3598 | Proces s { | ||
3599 | tr y { | ||
3600 | $msg = ' {0}{1,-20} : {2,-5} : {3,-8} : {4}' -f ( " " * $Ind ent), (Get -Date -For mat "yyyy- MM-dd HH:m m:ss"), $L evel.ToUpp er(), $Con soleForegr ound.ToUpp er(), $Mes sage | ||
3601 | if ($NoC onsoleOut -eq $False ) { | ||
3602 | swit ch ($Level ) { | ||
3603 | "Error" { Write-Erro r $Message } | ||
3604 | "Warn" { W rite-Warni ng $Messag e } | ||
3605 | "Info" { W rite-Host ('{0}{1}' -f (" " * $Indent), $Message) -Foregroun dColor $Co nsoleForeg round} | ||
3606 | } | ||
3607 | } | ||
3608 | if (-not $Path.Exi sts) { | ||
3609 | New- Item -Path $Path.Ful lName -Ite mType File -Force | Out-Null | ||
3610 | } | ||
3611 | if ($Clo bber) { | ||
3612 | $msg | Out-Fil e -FilePat h $Path -E ncoding $L ogEncoding -Force | ||
3613 | #$sw = [system .io.stream writer]::n ew($Path) | ||
3614 | #$sw .writeline ($msg) | ||
3615 | #$sw .close() | ||
3616 | } else { | ||
3617 | $msg | Out-Fil e -FilePat h $Path -E ncoding $L ogEncoding -Append | ||
3618 | #$sw = [system .io.stream writer]::n ew($Path) | ||
3619 | #$sw .writeline ($msg) | ||
3620 | #$sw .close() | ||
3621 | } | ||
3622 | if ($Eve ntLogName) { | ||
3623 | if ( -not $Even tSource) { | ||
3624 | $EventSour ce = ([IO. FileInfo] $MyInvocat ion.Script Name).Name | ||
3625 | } | ||
3626 | if(- not [Diagn ostics.Eve ntLog]::So urceExists ($EventSou rce)) { | ||
3627 | [Diagnosti cs.EventLo g]::Create EventSourc e($EventSo urce, $Eve ntLogName) | ||
3628 | } | ||
3629 | $log = New-Obj ect System .Diagnosti cs.EventLo g | ||
3630 | $log .set_log($ EventLogNa me) | ||
3631 | $log .set_sourc e($EventSo urce) | ||
3632 | swit ch ($Level ) { | ||
3633 | "Error" { $log.Write Entry($Mes sage, 'Err or', $Even tID) } | ||
3634 | "Warn" { $log.Write Entry($Mes sage, 'War ning', $Ev entID) } | ||
3635 | "Info" { $log.Write Entry($Mes sage, 'Inf ormation', $EventID) } | ||
3636 | } | ||
3637 | } | ||
3638 | } catch { | ||
3639 | throw "F ailed to c reate log entry in: $Path. The error was : $_ ." | ||
3640 | } | ||
3641 | } #End Process | ||
3642 | |||
3643 | End {} | ||
3644 | } | ||
3645 | |||
3646 | Export-Mod uleMember -function Get-SiteUR L | ||
3647 | Export-Mod uleMember -function Get-SiteWe b | ||
3648 | Export-Mod uleMember -function Set-SiteCo lumn -Alia s Add-Site Column, as c | ||
3649 | Export-Mod uleMember -function Add-SiteCo lumnToCT - Alias ascc t | ||
3650 | |||
3651 | Export-Mod uleMember -function Add-Facili tyWorkflow -Alias af wf | ||
3652 | Export-Mod uleMember -function Add-SiteCo llectionWo rkFlow | ||
3653 | Export-Mod uleMember -function Get-DateFr omDays | ||
3654 | Export-Mod uleMember -function Format-Lis tOutput | ||
3655 | Export-Mod uleMember -function Get-ListIn ternalName | ||
3656 | Export-Mod uleMember -function Get-SPList | ||
3657 | Export-Mod uleMember -function Remove-Dat aFromAList | ||
3658 | Export-Mod uleMember -function Deploy-Fea ture | ||
3659 | Export-Mod uleMember -function Update-Uti lMF | ||
3660 | Export-Mod uleMember -function Get-RAMSEn v | ||
3661 | Export-Mod uleMember -function New-RAMSEn v | ||
3662 | Export-Mod uleMember -function Update-RAM SEnv | ||
3663 | Export-Mod uleMember -function Get-RAMSSh arePointIn stallInfo | ||
3664 | Export-Mod uleMember -function Get-Facili tySites | ||
3665 | Export-Mod uleMember -function New-RAMSGr oup -Alias nrg | ||
3666 | Export-Mod uleMember -function Add-Facili tyGroup -A lias afg | ||
3667 | Export-Mod uleMember -Function RunSQL-Ret urnInt -Al ias rsri | ||
3668 | Export-Mod uleMember -Function RunSQL-Ret urnDR -Ali as rsrdr | ||
3669 | Export-Mod uleMember -Function Remove-Wor kFlow -Ali as remwf | ||
3670 | Export-Mod uleMember -Function Rename-Lis t -Alias r enList | ||
3671 | Export-Mod uleMember -Function Clone-Cale ndar -Alia s cloneCal | ||
3672 | Export-Mod uleMember -Function Remove-Cal endarColum ns -Alias RCC | ||
3673 | |||
3674 | Export-Mod uleMember -Function Remove-Fac ilitySiteP ages | ||
3675 | Export-Mod uleMember -Function Remove-Fac ilitySiteA ssets | ||
3676 | |||
3677 | #added on 03/16/2018 | ||
3678 | Export-Mod uleMember -Function New-SpList View | ||
3679 | Export-Mod uleMember -Function Update-SpL istView | ||
3680 | |||
3681 | #added on 03/17/2018 | ||
3682 | Export-Mod uleMember -function Remove-Con tentTypeFr omList | ||
3683 | #Export-Mo duleMember -function Set-SiteC olumnLooku p | ||
3684 | Export-Mod uleMember -function Add-SiteCo lumnToCTBy Title | ||
3685 | |||
3686 | #added on 03/19/2018 | ||
3687 | Export-Mod uleMember -function Remove-Col umnFromLis t | ||
3688 | |||
3689 | #added on 04/10/2018 | ||
3690 | Export-Mod uleMember -function Set-SiteCo lumnLookup | ||
3691 | |||
3692 | #added on 04/13/2018 | ||
3693 | Export-Mod uleMember -function Update-Sit eColumnLoo kup | ||
3694 | |||
3695 | #added on 4/15/2018 | ||
3696 | Export-Mod uleMember -Function Remove-Sit ePages | ||
3697 | Export-Mod uleMember -Function Remove-Sit eAssets | ||
3698 | |||
3699 | #added on 5/01/2018 | ||
3700 | Export-Mod uleMember -Function Set-Facili tyListPerm issionAndV ersioning | ||
3701 | |||
3702 | #added on 5/07/2018 | ||
3703 | Export-Mod uleMember -Function Import-RAM SUsers | ||
3704 | |||
3705 | #added on 5/10/2018 | ||
3706 | Export-Mod uleMember -Function New-Meetin gMinuteLoo kup | ||
3707 | Export-Mod uleMember -Function Update-Cal endarView | ||
3708 | Export-Mod uleMember -Function New-SPList | ||
3709 | |||
3710 | #added on 5/31/2018 | ||
3711 | Export-Mod uleMember -Function New-SSISDB | ||
3712 | |||
3713 | #added on 6/01/2018 | ||
3714 | Export-Mod uleMember -Function Install-SS ISAdapter | ||
3715 | Export-Mod uleMember -Function New-SpFaci lityListVi ew | ||
3716 | |||
3717 | #added on 6/02/2018 | ||
3718 | Export-Mod uleMember -Function Get-RAMSEn vName | ||
3719 | |||
3720 | #added on 7/12/2018 | ||
3721 | Export-Mod uleMember -Function Get-FullHe lp | ||
3722 | Export-Mod uleMember -Function Write-Log | ||
3723 | Export-Mod uleMember -Function Run-Script | ||
3724 | #added on 7/12/2018 | ||
3725 | Export-Mod uleMember -function Get-MySite URL | ||
3726 | Export-Mod uleMember -function Get-MySite Web | ||
3727 | |||
3728 | #added on 7/19/2018 | ||
3729 | Export-Mod uleMember -function Add-Reusab leWorkFlow ToContentT ype | ||
3730 | |||
3731 | #added on 8/8/2018 | ||
3732 | Export-Mod uleMember -function Deploy-Far mERFeature | ||
3733 | |||
3734 | #added on 8/8/2018 | ||
3735 | Export-Mod uleMember -function Deploy-Far mWFFeature | ||
3736 | Export-Mod uleMember -function Add-EventR eceiverToC ontentType | ||
3737 |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.