forked from timmcmic/DLConversionV2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStart-ArchiveFiles.ps1
More file actions
111 lines (82 loc) · 3.19 KB
/
Start-ArchiveFiles.ps1
File metadata and controls
111 lines (82 loc) · 3.19 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<#
.SYNOPSIS
This function archives the files associated with the distribution list migration.
.DESCRIPTION
his function archives the files associated with the distribution list migration.
.PARAMETER isSuccess
.OUTPUTS
No return.
.EXAMPLE
start-archiveFiles -isSuccess:$TRUE
#>
Function Start-ArchiveFiles
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory = $true)]
[boolean]$isSuccess=$FALSE,
[Parameter(Mandatory = $true)]
[string]$logFolderPath=$NULL,
[Parameter(Mandatory = $false)]
[boolean]$isHealthCheck=$FALSE
)
#Output all parameters bound or unbound and their associated values.
write-functionParameters -keyArray $MyInvocation.MyCommand.Parameters.Keys -parameterArray $PSBoundParameters -variableArray (Get-Variable -Scope Local -ErrorAction Ignore)
out-logFile -string "Archiving files associated with run."
if ($isHealthCheck -eq $TRUE)
{
$functionDate = Get-Date -Format FileDateTime
$functionDate = "PreReqTest-"+$functionDate
}
else
{
$functionDate = Get-Date -Format FileDateTime
}
$functionNameSplit = $global:logFile.split("\")
out-logfile -string "Split string for group name."
out-logfile -string $functionNameSplit
$functionNameSplit = $functionNameSplit[-1].split(".")
out-logfile -string "Split string for group name."
out-logfile -string $functionNameSplit
if ($isSuccess -eq $TRUE)
{
write-shamelessPlug
out-logfile -string "Success - renaming directory."
$functionFolderName = $functionNameSplit[0]+"-Success"
$functionFolderName = $functionDate+"-"+$functionFolderName
$functionOriginalPath= $logFolderPath+$global:staticFolderName
out-logfile -string $functionFolderName
out-logfile -string $functionOriginalPath
rename-item -path $functionOriginalPath -newName $functionFolderName
}
else
{
write-shamelessPlug
out-logfile -string "FAILED - renaming directory."
$functionFolderName = $functionNameSplit[0]+"-FAILED"
$functionFolderName = $functionDate+"-"+$functionFolderName
$functionOriginalPath= $logFolderPath+$global:staticFolderName
out-logfile -string $functionFolderName
out-logfile -string $functionOriginalPath
$doCounter=0
$stopLoop=$FALSE
do {
try {
rename-item -path $functionOriginalPath -newName $functionFolderName -errorAction Stop
$stopLoop=$true
}
catch {
if ($doCounter -gt 5)
{
$stopLoop-$TRUE
}
else
{
start-sleep -s 5
$doCounter=$doCounter+1
}
}
} until ($stopLoop -eq $TRUE)
}
}