From f8bc020aa739a491299a90a73c44cec899017b96 Mon Sep 17 00:00:00 2001 From: eeckert Date: Thu, 28 Sep 2023 15:58:07 -0600 Subject: [PATCH] add folder refesh after 15 days as well --- Get-ProjectFolders.ps1 | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Get-ProjectFolders.ps1 b/Get-ProjectFolders.ps1 index 2758f85..4861f4e 100644 --- a/Get-ProjectFolders.ps1 +++ b/Get-ProjectFolders.ps1 @@ -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