add folder refesh after 15 days as well

This commit is contained in:
Erik Eckert 2023-09-28 15:58:07 -06:00
parent fb1225060e
commit f8bc020aa7

View File

@ -101,23 +101,33 @@ $OfficeList | ForEach-Object -parallel {
# Write-Progress @CurentLoopProgress
}
elseif ($result.Length -ge 5) {
$RefreshDays = -15
$Server = $_.FullName.Substring(1, 4) -replace (':|\\', '')
$Path = $_.FullName.Replace("'", "`'") #SQL Formatted Path
$Path = $Path.Replace("X:\", "\\mpe.ca\datadrive\")
$projectnumber = $result.tostring()
$DBConnect = New-SqliteConnection -DataSource $PathToDB_Copy
$Query = "Select Project FROM FolderData where Project = '$ProjectNumber' AND Server = '$Server' AND Path = `"$Path`";"
$Query = "Select Project,fld_LastRefresh FROM FolderData where Project = '$ProjectNumber' AND Server = '$Server' AND Path = `"$Path`";"
$sql_result = Invoke-SqliteQuery -DataSource $PathToDB_Copy -Query $Query
if (($sql_result.project -eq $null)) {
if (($sql_result.project -eq $null) -or ($sql_result.fld_LastRefresh -le (Get-Date).AddDays($RefreshDays).ToShortDateString())) {
$CurentLoopProgress = @{
ID = $JobID
Activity = "Loading Telemetry for " + $_.FullName
Activity = "Loading Telemetry for " + $_.FullName
PercentComplete = 75
}
Write-Progress @CurentLoopProgress
if ($sql_result.project -ne $null) {
# found a record, but needs updating - delete old record from DB
$Query = "Delete from FolderData WHERE '$ProjectNumber' AND Server = '$Server' AND Path = `"$Path`""
Invoke-SqliteQuery -DataSource $PathToDB_Copy -Query $Query
}
$result3 = [Regex]::Matches($_.FullName, "^(.*[\\\/])") # This gets everything up the last slash, thus the "parent"
$FolderPath_Data = Get-ChildItem -Path $_.FullName -File -Depth 50 -Recurse
@ -145,6 +155,7 @@ $OfficeList | ForEach-Object -parallel {
FileLastAccess = $folder_LastAccess
Status = $null # added to support Migration Status
fld_MigrationID = $null
fld_LastRefresh = (Get-Date).ToShortDateString()
} | Out-DataTable
Invoke-SQLiteBulkCopy -DataSource $PathToDB_Copy -Table "FolderData" -DataTable $out -Force