From f507c7674060fab6b0e619a2f9d357fdf9dcedeb Mon Sep 17 00:00:00 2001 From: eeckert Date: Mon, 2 Oct 2023 16:17:35 -0600 Subject: [PATCH] missed one --- Get-ProjectFolders.ps1 | 119 ++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 73 deletions(-) diff --git a/Get-ProjectFolders.ps1 b/Get-ProjectFolders.ps1 index 6b2be4a..f53d999 100644 --- a/Get-ProjectFolders.ps1 +++ b/Get-ProjectFolders.ps1 @@ -73,88 +73,61 @@ $OfficeList | ForEach-Object -parallel { # Write-Progress @CurentLoopProgress - $projectNumber = '' + # thank you ChatGPT $string = $_.FullName - $regex = "\\(\d+(-\d+)*)" - $matches = [regex]::Matches($string, $regex) - $result = "" - foreach ($match in $matches) { - $result += $match.Groups[1].Value - if ($match.Groups[2].Success) { - $result += $match.Groups[2].Value + $RefreshDays = -15 - (Get-Random -Maximum 5) + $Server = $_.FullName.Substring(1, 4) -replace (':|\\', '') + $Path = $_.FullName.Replace("'", "`'") #SQL Formatted Path + $Path = $Path.Replace("X:\", "\\mpe.ca\datadrive\") + $DBConnect = New-SqliteConnection -DataSource $PathToDB_Copy + $Query = "Select fld_LastRefresh FROM FolderData where Server = '$Server' AND Path = `"$Path`";" + $sql_result = Invoke-SqliteQuery -DataSource $PathToDB_Copy -Query $Query + + + if (($sql_result.fld_LastRefresh -le (Get-Date).AddDays($RefreshDays).ToShortDateString())) { + $CurentLoopProgress = @{ + ID = $JobID + Activity = "Loading Telemetry for " + $_.FullName + PercentComplete = 75 } - # if ($match.Groups[3].Success) { - # $result += $match.Groups[3].Value - # } - } - # / Thank you Chat GPT - # $result = $result -replace ('-','') - - - if ($result.Length -lt 5 ) { - # $CurentLoopProgress = @{ - # ID = $JobID - # Activity = $_.FullName + " Not a Project" - # } - - # Write-Progress @CurentLoopProgress - } - elseif ($result.Length -ge 5) { - $RefreshDays = -15 - (Get-Random -Maximum 5) - - $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 fld_LastRefresh FROM FolderData where Server = '$Server' AND Path = `"$Path`";" - $sql_result = Invoke-SqliteQuery -DataSource $PathToDB_Copy -Query $Query - - - if (($sql_result.fld_LastRefresh -le (Get-Date).AddDays($RefreshDays).ToShortDateString())) { - $CurentLoopProgress = @{ - ID = $JobID - Activity = "Loading Telemetry for " + $_.FullName - PercentComplete = 75 - } - Write-Progress @CurentLoopProgress + Write-Progress @CurentLoopProgress - $result3 = [Regex]::Matches($_.FullName, "^(.*[\\\/])") # This gets everything up the last slash, thus the "parent" - $FolderPath_Data = Get-ChildItem -Path $_.FullName -File -Depth 50 -Recurse - $folder_Parent = $result3.value.replace("'", "`'") #SQL Formatting - $folder_Parent = $folder_Parent.Replace("X:\", "\\mpe.ca\datadrive\") - $folder_FileSize = ($FolderPath_Data | Measure -sum Length).sum / 1024 / 1024 / 1024 - $folder_FileCount = ($FolderPath_Data | measure).Count - $folder_LastWrite = ($FolderPath_Data | measure LastWriteTime -Maximum).Maximum - $folder_LastAccess = ($FolderPath_Data | measure LastAccessTime -Maximum).Maximum + $result3 = [Regex]::Matches($_.FullName, "^(.*[\\\/])") # This gets everything up the last slash, thus the "parent" + $FolderPath_Data = Get-ChildItem -Path $_.FullName -File -Depth 50 -Recurse + $folder_Parent = $result3.value.replace("'", "`'") #SQL Formatting + $folder_Parent = $folder_Parent.Replace("X:\", "\\mpe.ca\datadrive\") + $folder_FileSize = ($FolderPath_Data | Measure -sum Length).sum / 1024 / 1024 / 1024 + $folder_FileCount = ($FolderPath_Data | measure).Count + $folder_LastWrite = ($FolderPath_Data | measure LastWriteTime -Maximum).Maximum + $folder_LastAccess = ($FolderPath_Data | measure LastAccessTime -Maximum).Maximum - if ($folder_FileSize -le 0 -or $folder_FileCount -eq 0) { + if ($folder_FileSize -le 0 -or $folder_FileCount -eq 0) { - #Let's ignore Null Values - } - else { - - $out = [PSCustomObject]@{ - Server = $Server - Parent = $folder_Parent - Path = $Path - FileCount = $folder_FileCount - FileSize = $folder_FileSize - FileLastWrite = $folder_LastWrite - 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 - - } + #Let's ignore Null Values + } + else { + + $out = [PSCustomObject]@{ + Server = $Server + Parent = $folder_Parent + Path = $Path + FileCount = $folder_FileCount + FileSize = $folder_FileSize + FileLastWrite = $folder_LastWrite + 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 + } - $DBConnect.Close() } + $DBConnect.Close() + Write-Progress @CurentLoopProgress -Completed } Write-Progress @ServerProgress -Completed