-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathap-tools-RunMultipleBatchesArchiveAndDelete.ps1
65 lines (56 loc) · 1.71 KB
/
ap-tools-RunMultipleBatchesArchiveAndDelete.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]
$APDatabaseServer,
[Parameter(Mandatory)]
[ValidateScript({
$inputDate = $_
$twoYearsAgo = (Get-Date).AddYears(-2)
if ($inputDate -lt $twoYearsAgo) {
$true
}
else {
throw "ArchiveOnlyRequestsOlderThanThis must be older than 2 years"
}
})]
[datetime]
$ArchiveOnlyRequestsOlderThanThis,
[Parameter(Mandatory)]
[ValidateScript({
$inputAmount = $_
if ($inputAmount -le 300) {
$true
}
else {
throw "HowManyRequestsToArchiveAndDelete must be 300 or less"
}
})]
[Int]
$HowManyRequestsToArchiveAndDelete,
[string]
$ArchivePath = '.\',
[switch]
$UnsafeMode,
[switch]
$DontUseTrustServerCertificate,
[int]
$batchCount,
[switch]
$OlderThanAP310
)
for ($i = 1; $i -le $batchCount; $i++) {
try {
Write-Host "Running Batch $i / $batchCount"
$result = . '.\ap-tools-ArchiveAndDeleteRequests.ps1' -APDatabaseServer $APDatabaseServer -ArchiveOnlyRequestsOlderThanThis $ArchiveOnlyRequestsOlderThanThis -HowManyRequestsToArchiveAndDelete $HowManyRequestsToArchiveAndDelete -UnsafeMode:$UnsafeMode -DontUseTrustServerCertificate:$DontUseTrustServerCertificate -InformationAction:$InformationPreference -OlderThanAP310:$OlderThanAP310
}
catch {
if ($PSItem.Exception.Message -eq 'No Requests in scope.') {
Write-Host $PSItem.Exception.Message
break
}
Write-Error $PSItem.Exception
break
}
}
Write-Host "Batches completed."