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_CleanHistory.psm1 | Wed Aug 22 15:43:34 2018 UTC |
2 | RAMS-2.3.0.zip\RAMS-2.3.0\ps\module | RAMS_Module_CleanHistory.psm1 | Fri Nov 9 14:41:57 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 3 | 406 |
Changed | 2 | 4 |
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 | if((Get-Mo dule -Name RAMS_Modu le_Util) - eq $null) { | |
2 | Import -Module .\ RAMS_Modul e_Util.psd 1 | |
3 | } | |
4 | $rundate = Get-Date -UFormat " %Y%m%d%H%M " | |
5 | $Global:cl eanLogFile Name = "Cl eanHistory _$env:COMP UTERNAME.$ rundate.lo g" | |
6 | if ($Globa l:diretory Name -eq $ null) { | |
7 | $Globa l:diretory Name = Spl it-Path -P ath $MyInv ocation.My Command.Pa th -Parent | |
8 | } | |
9 | $cleanHist oryPath = join-path -path $Glo bal:direto ryName -ch ildpath $G lobal:clea nLogFileNa me | |
10 | ||
11 | Set-Strict Mode -Vers ion Latest | |
12 | ||
13 | $ArrayList = New-Obj ect System .Collectio ns.ArrayLi st | |
14 | ||
15 | function G et-ColumnV alueFromAL ist ($Site , $subSite , $filterD ate, $list Url, $list Name, $lis tColumnNam e) { | |
16 | #get a collectio n of ids | |
17 | $items ToDelete = New-Objec t System.C ollections .ArrayList | |
18 | $list = Get-SPLi st -web $S ite -Name $listName -Url $list Url -subWe b $subSite | |
19 | #get a pplication list | |
20 | if($li st -ne $nu ll) { | |
21 | #G et all ite ms in this list and save them to a varia ble | |
22 | $i tems = $li st.items | |
23 | $i temCount = 0 | |
24 | #G o through all items | |
25 | Wr ite-log -m essage "To tal Items in the $($ list.Entit yTypeName) : $($item s.Count)" -consoleFo reground G reen -Path $cleanHis toryPath | |
26 | fo reach($ite m in $item s) { | |
27 | if($item ["Created" ] -lt $fil terDate) { | |
28 | #add each item id to the delete li st | |
29 | Writ e-log -mes sage "Add item $item Count fro m the list for Study : $($item[ "Title"]) on $($item ["Created" ])" -conso leForegrou nd Cyan -P ath $clean HistoryPat h | |
30 | $ite msToDelete .Add($item [$listColu mnName]) | |
31 | $ite mCount ++; | |
32 | } | |
33 | } | |
34 | #n ow start d eleting th ose items | |
35 | if ($itemCoun t -eq 0) { | |
36 | Write-lo g -message "Nothing to delete, count: $i temCount" -consoleFo reground y ellow -Pat h $cleanHi storyPath | |
37 | r eturn | |
38 | } | |
39 | Wri te-log -me ssage "Tot al items t o be delet ed $itemCo unt" -cons oleForegro und yellow -Path $cl eanHistory Path | |
40 | } else { | |
41 | Wr ite-log -m essage "No list foun d by the n ame: $list Url" -cons oleForegro und red -P ath $clean HistoryPat h | |
42 | } | |
43 | return $itemsToD elete | |
44 | } | |
45 | ||
46 | function R emove-Data FromAListB yColumn ($ Site, $sub Site, $Col umnSet, $l istUrl, $l istName, $ listColumn Name) { | |
47 | #get a collectio n of ids | |
48 | $items ToDelete = New-Objec t System.C ollections .ArrayList | |
49 | $list = Get-SPLi st -web $S ite -Name $listName -Url $list Url -subWe b $subSite | |
50 | #get a pplication list | |
51 | if($li st -ne $nu ll) { | |
52 | #G et all ite ms in this list and save them to a varia ble | |
53 | $i tems = $li st.items | |
54 | $l istTitle = $list.Tit le | |
55 | $i temCount = 0 | |
56 | #G o through all items | |
57 | Wr ite-log -m essage "To tal Items in the $($ list.Entit yTypeName) : $($item s.Count)" -consoleFo reground G reen -Path $cleanHis toryPath | |
58 | fo reach($ite m in $item s) { | |
59 | foreach( $col in $C olumnSet) { | |
60 | $x = $item.Url | |
61 | if($ x.IndexOf( "/Study") -gt 0) { | |
62 | $studyId = $x.Substr ing($x.Ind exOf("/")+ 1,$x.Index Of("/Study ")-$x.Inde xOf("/")-1 ) | |
63 | if($studyI d -eq $col ) { | |
64 | if ($i tem.Title -ne $null) { | |
65 | $i temDescrip tion = $it em.Title | |
66 | } else if ($item. Name -ne $ null ) { | |
67 | $i temDescrip tion = $it em.Name | |
68 | } else { | |
69 | $i temDescrip tion = "Un known Titl e or Name" | |
70 | } | |
71 | #add e ach item i d to the d elete list | |
72 | Write- log -messa ge "$itemC ount. Add item.Id $( $item.Id) from the l ist $listT itle for S tudy: $ite mDescripti on on $($i tem["Creat ed"])" -co nsoleForeg round Cyan -Path $cl eanHistory Path | |
73 | $items ToDelete.A dd($item.I D) | |
74 | $itemC ount ++; | |
75 | } | |
76 | } | |
77 | } | |
78 | } | |
79 | #n ow start d eleting th ose items | |
80 | if ($itemCoun t -eq 0) { | |
81 | Write-lo g -message "Nothing to delete, count: $i temCount" -consoleFo reground Y ellow -Pat h $cleanHi storyPath | |
82 | r eturn | |
83 | } | |
84 | Wr ite-log -m essage "To tal items to be dele ted $itemC ount" -con soleForegr ound Yello w -Path $c leanHistor yPath | |
85 | $d eleteItemC ount = 0 | |
86 | fo reach($ite mToDelete in $itemsT oDelete) { | |
87 | Write-lo g -message "$($delet eItemCount ) of $($it emCount). Deleting i tem.Id $it emToDelete from $lis tTitle lis t." -conso leForegrou nd Yellow -Path $cle anHistoryP ath | |
88 | $items.D eleteItemB yId($itemT oDelete); | |
89 | deleteIt emCount++ | |
90 | } | |
91 | $i tems.Updat e(); | |
92 | $l ist.Update (); | |
93 | Wr ite-log -m essage "To tal number of items in $listTi tle after delete: $( $list.item s.Count)" -consoleFo reground G reen -Path $cleanHis toryPath | |
94 | } else { | |
95 | Wr ite-log -m essage "No list foun d by the n ame: $list Url" -cons oleForegro und red -P ath $clean HistoryPat h | |
96 | } | |
97 | return $itemsToD elete | |
98 | } | |
99 | ||
100 | function R emove-RAMS HistoryDat a ($cleanD ate, $dbSe rver) { | |
101 | #get s ite collec tion | |
102 | #$site = Get-SPS ite -Limit All | Sel ect-String IRBApplic ations | |
103 | $site= Get-SiteU RL | |
104 | $x = $ site.ToStr ing(); | |
105 | $url = $x.Substr ing($x.Ind exOf("=")+ 1) | |
106 | #$w = Get-SPWeb $url | |
107 | $w = G et-SiteWeb | |
108 | ||
109 | #filte r by days | |
110 | $filte rPriorDate = $cleanD ate | |
111 | write- log -messa ge "Delete data befo re $filter PriorDate" -consoleF oreground magenta -P ath $clean HistoryPat h | |
112 | ||
113 | #Delet e Applicat ion list f or older s tudies. | |
114 | $listU rl = $url + "/Lists/ Applicatio n/AllItems .aspx" | |
115 | $listO fStudies = Get-Colum nValueFrom AList -Sit e $w -filt erDate $fi lterPriorD ate -listU rl $listUr l -listCol umnName "S tudy_ID" | |
116 | ||
117 | Remove -DataFromA List -Site $w -filte rDate $fil terPriorDa te -listUr l $listUrl | |
118 | ||
119 | #Delet e workflow task list | |
120 | $listU rl = $url + "/Workfl owTasks/Al lItems.asp x" | |
121 | Remove -DataFromA List -Site $w -filte rDate $fil terPriorDa te -listUr l $listUrl | |
122 | ||
123 | #Delet e Shared D ocs for th e same set of studie s | |
124 | $listU rl = $url + "/Shared %20Documen ts/Forms/A llItems.as px" | |
125 | Remove -DataFromA List -Site $w -filte rDate $fil terPriorDa te -listUr l $listUrl | |
126 | Remove -DataFromA ListByColu mn -Site $ w -ColumnS et $listOf Studies -l istUrl $li stUrl -lis tColumnNam e "Name" | |
127 | ||
128 | #delet e items fr om list at sub-site level | |
129 | $listB ucket = @( | |
130 | "F ullBoardRe viewCalend ar", | |
131 | "C ommitteeMi nutes", | |
132 | "A pplication ", | |
133 | "D ataSharing Repository Agreements ", | |
134 | "I ACUC Calen dar", | |
135 | "R DC Calenda r", | |
136 | "S RSCalendar ", | |
137 | "S C1Calendar ", | |
138 | "S C2Calendar ", | |
139 | "S C3Calendar ", | |
140 | "A genda", | |
141 | "A pplication Facilitylo okup", | |
142 | "A ppointment s", | |
143 | "C ommitteeMe mbers", | |
144 | "C ommitteeRo ster", | |
145 | "C ommitteeTo pics", | |
146 | "C ommitteeWo rkflow", | |
147 | "L abs", | |
148 | "P roperty", | |
149 | "R eviews" | |
150 | ); | |
151 | ||
152 | $formB ucket = @( | |
153 | "I ACUCDocume nts", | |
154 | "R DCAgenda", | |
155 | "R DCDocument s", | |
156 | "R COChecklis ts", | |
157 | "C hecklists" , | |
158 | "S RSDocument s", | |
159 | "D ocuments", | |
160 | "S C1Document s", | |
161 | "S C2Document s", | |
162 | "S C3Document s", | |
163 | "A nimalFacil ityDocumen ts", | |
164 | "I nvestigato rDocuments ", | |
165 | "M eetingMinu tes", | |
166 | "S tudyReview ", | |
167 | "W orkflowTas ks" | |
168 | ); | |
169 | ||
170 | foreac h($sub in $w.Webs) { | |
171 | #D elete list data | |
172 | fo reach($lis tEgg in $l istBucket) { | |
173 | $listUrl = $sub.ur l + "/List s/" + $lis tEgg + "/A llItems.as px" | |
174 | Remove-D ataFromALi st -filter Date $filt erPriorDat e -listNam e $listEgg -listUrl $listUrl - subSite $s ub | |
175 | } | |
176 | #D elete form data | |
177 | fo reach($for mEgg in $f ormBucket) { | |
178 | $listUrl = $sub.ur l + "/" + $formEgg + "/Forms/A llItems.as px" | |
179 | Remove-D ataFromALi st -filter Date $filt erPriorDat e -listNam e $formEgg -listUrl $listUrl - subSite $s ub | |
180 | } | |
181 | } | |
182 | #clean from sql server | |
183 | $recAf fected = RunSQL-Ret urnInt -sq lQuery "ex ec DataCle anup @cuto ffdate='$c leandate'" -dbServer $dbServer | |
184 | write- log -messa ge "Total $recAffect ed Studies have been deleted f rom the RA MS user da tabase" -c onsoleFore ground yel low -Path $cleanHist oryPath | |
185 | } | |
186 | ||
187 | Export-Mod uleMember Remove-RAM SHistoryDa ta | |
188 | ||
189 | <# | |
190 | e.g. Remov e-RAMSHist oryData -c leanDate " 12/30/2015 12:56:20" -dbServer DN S
|
|
191 | Set-Locati on .\modul e | |
192 | New-Module Manifest - Path .\RAM S_Module_C leanHistor y.psd1 -Mo duleVersio n 1.1.0 -A uthor "Chi ta Nilak, ByLight" - RootModule .\RAMS_Mo dule_Clean History.ps m1 -Descri ption "RAM S Utility Functions" -CompanyN ame " DN S" -Verbos e | |
193 | cd.. | |
194 | if((Get-Mo dule -Name RAMS_Modu le_CleanHi story) -ne $null) { | |
195 | Remove -Module -N ame RAMS_M odule_Clea nHistory | |
196 | } | |
197 | try { | |
198 | Import -Module .\ RAMS_Modul e_CleanHis tory.psd1 | |
199 | } | |
200 | catch { | |
201 | Write- log -messa ge "Host: $env:COMPU TERNAME is not a Ser ver, Share Point is n ot install ed on this computer. ..ignore, informatio n only." - consoleFor eground ye llow -Path $cleanHis toryPath | |
202 | #do no thing. | |
203 | } | |
204 | ||
205 | #> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.