-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_Functions.ps1
More file actions
61 lines (53 loc) · 2.2 KB
/
_Functions.ps1
File metadata and controls
61 lines (53 loc) · 2.2 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
function Get-ExceptionMessage($message){
return ((Get-Date -Format "yyyy-MM-dd HH:mm:ss") + " -> " + $message)
}
function Write-LogInfo ($unhandledItems, $errorsPath) {
Write-Output "Script finished!"
if($unhandledItems.Count -gt 0){
$errorSummarStartMessage = "- - - - - E R R O R S U M M A R Y S T A R T - - - - -"
$errorSummarEndMessage = "- - - - - - E R R O R S U M M A R Y E N D - - - - - -"
Write-Output $errorSummarStartMessage
foreach ($unhandledItem in $unhandledItems){ Write-Output ($unhandledItem) }
Write-Output $errorSummarEndMessage
Add-Content -Path $errorsPath -Value $errorSummarStartMessage
foreach ($unhandledItem in $unhandledItems){ Add-Content -Path $errorsPath -Value ($unhandledItem) }
Add-Content -Path $errorsPath -Value $errorSummarEndMessage
Write-Output ("Error logs saved to file: " + $errorsPath)
} else {
Write-Output "No errors when running script!"
}
}
### Set - File is not fully processed ###
function Set-ProgressStarted($progressFilePath, $progressStartText, $itemname, $i){
Add-Content -Path $progressFilePath -Value $progressStartText
Add-Content -Path $progressFilePath -Value $item.Name
Add-Content -Path $progressFilePath -Value $i
}
### Set - File is fully processed ###
function Set-ProgressCompleted($progressFilePath, $progressEndText, $deletionReadyPath, $deletionPath, $operationType){
Add-Content -Path $progressFilePath -Value $progressEndText
Add-Content -Path $deletionReadyPath -Value $deletionPath
Add-Content -Path $deletionReadyPath -Value $operationType
}
### Get last file not fully processed ###
function Get-Progress($progressFilePath){
$beginFile = ""
$beginIndex = "1"
if(Test-Path $progressFilePath){
$progressFileContent = Get-Content -Path $progressFilePath
$fileInProgressSwitch = $false
foreach($line in $progressFileContent){
if($line -eq $progressStartText){
$fileInProgressSwitch = $true
} elseif($line -eq $progressEndText){
$fileInProgressSwitch = $false
$beginFile = ""
} elseif($fileInProgressSwitch -eq $true -and !($beginFile)){
$beginFile = $line
} elseif($fileInProgressSwitch -eq $true -and $beginFile){
$beginIndex = $line
}
}
}
return @($beginFile, $beginIndex)
}