-
Notifications
You must be signed in to change notification settings - Fork 2
/
checkFileExistance.ps1
65 lines (58 loc) · 1.58 KB
/
checkFileExistance.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
$file1 = "\\path\to\file-txt"
$file2 = "\\path\to\file-txt"
$file3 = "\\path\to\file-txt"
$file4 = "\\path\to\file-txt"
$file5 = "\\fifth\file-txt"
[array]$missingFiles;
# Used by logging
$scriptName = Split-Path -Path $MyInvocation.MyCommand.Definition -Leaf
[int]$testNum = 0
[array]$fileArray = $file1, $file2, $file3, $file4, $file5,
$allgood = [bool]$false
$truetest = [bool]$true
$errorcounter = 0;
function checkExist{
echo Checking if all files exist
for($i=0;$i -lt $fileArray.Count; $i++){
$currentFile = $fileArray[$i]
$result = Test-Path $fileArray[$i]
if($result -eq $false){
$missingFiles += $currentFile + "; ";
waitSixMinutes;
}
else{
echo $fileArray[$i] exists;
$testNum++
if ($testNum -eq $fileArray.Count){echo All files present}
continue;
}
}
}
# Logging
function logErrors{
$Currentdate = Get-Date -Format('ddMMyyyyHHmm')
$LogFolderPath= "route\to\logfolder\"
$LogFile = $LogFolderPath + $scriptName + "_" + $Currentdate + ".log"
$errorMessage = "Poll failed on " + $Currentdate + " Missing: "
echo $LogFile
New-Item -ItemType "file" -Path $LogFile -Value ($errorMessage + $missingFiles)
throw "File Missing";
}
function waitSixMinutes
{
if($errorcounter -eq 2){
logErrors;
Exit;
}
echo File Missing
Start-Sleep -Seconds 360
$errorcounter = $errorcounter + 1;
checkExist;
}
# Call main check
function main{
checkExist
Exit
}
main;
Exit