missed one
This commit is contained in:
parent
d5219e90f4
commit
f507c76740
@ -73,88 +73,61 @@ $OfficeList | ForEach-Object -parallel {
|
|||||||
# Write-Progress @CurentLoopProgress
|
# Write-Progress @CurentLoopProgress
|
||||||
|
|
||||||
|
|
||||||
$projectNumber = ''
|
|
||||||
# thank you ChatGPT
|
# thank you ChatGPT
|
||||||
$string = $_.FullName
|
$string = $_.FullName
|
||||||
$regex = "\\(\d+(-\d+)*)"
|
$RefreshDays = -15 - (Get-Random -Maximum 5)
|
||||||
$matches = [regex]::Matches($string, $regex)
|
$Server = $_.FullName.Substring(1, 4) -replace (':|\\', '')
|
||||||
$result = ""
|
$Path = $_.FullName.Replace("'", "`'") #SQL Formatted Path
|
||||||
foreach ($match in $matches) {
|
$Path = $Path.Replace("X:\", "\\mpe.ca\datadrive\")
|
||||||
$result += $match.Groups[1].Value
|
$DBConnect = New-SqliteConnection -DataSource $PathToDB_Copy
|
||||||
if ($match.Groups[2].Success) {
|
$Query = "Select fld_LastRefresh FROM FolderData where Server = '$Server' AND Path = `"$Path`";"
|
||||||
$result += $match.Groups[2].Value
|
$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"
|
$result3 = [Regex]::Matches($_.FullName, "^(.*[\\\/])") # This gets everything up the last slash, thus the "parent"
|
||||||
$FolderPath_Data = Get-ChildItem -Path $_.FullName -File -Depth 50 -Recurse
|
$FolderPath_Data = Get-ChildItem -Path $_.FullName -File -Depth 50 -Recurse
|
||||||
$folder_Parent = $result3.value.replace("'", "`'") #SQL Formatting
|
$folder_Parent = $result3.value.replace("'", "`'") #SQL Formatting
|
||||||
$folder_Parent = $folder_Parent.Replace("X:\", "\\mpe.ca\datadrive\")
|
$folder_Parent = $folder_Parent.Replace("X:\", "\\mpe.ca\datadrive\")
|
||||||
$folder_FileSize = ($FolderPath_Data | Measure -sum Length).sum / 1024 / 1024 / 1024
|
$folder_FileSize = ($FolderPath_Data | Measure -sum Length).sum / 1024 / 1024 / 1024
|
||||||
$folder_FileCount = ($FolderPath_Data | measure).Count
|
$folder_FileCount = ($FolderPath_Data | measure).Count
|
||||||
$folder_LastWrite = ($FolderPath_Data | measure LastWriteTime -Maximum).Maximum
|
$folder_LastWrite = ($FolderPath_Data | measure LastWriteTime -Maximum).Maximum
|
||||||
$folder_LastAccess = ($FolderPath_Data | measure LastAccessTime -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
|
#Let's ignore Null Values
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
$out = [PSCustomObject]@{
|
$out = [PSCustomObject]@{
|
||||||
Server = $Server
|
Server = $Server
|
||||||
Parent = $folder_Parent
|
Parent = $folder_Parent
|
||||||
Path = $Path
|
Path = $Path
|
||||||
FileCount = $folder_FileCount
|
FileCount = $folder_FileCount
|
||||||
FileSize = $folder_FileSize
|
FileSize = $folder_FileSize
|
||||||
FileLastWrite = $folder_LastWrite
|
FileLastWrite = $folder_LastWrite
|
||||||
FileLastAccess = $folder_LastAccess
|
FileLastAccess = $folder_LastAccess
|
||||||
Status = $null # added to support Migration Status
|
Status = $null # added to support Migration Status
|
||||||
fld_MigrationID = $null
|
fld_MigrationID = $null
|
||||||
fld_LastRefresh = (Get-Date).ToShortDateString()
|
fld_LastRefresh = (Get-Date).ToShortDateString()
|
||||||
} | Out-DataTable
|
} | Out-DataTable
|
||||||
|
|
||||||
Invoke-SQLiteBulkCopy -DataSource $PathToDB_Copy -Table "FolderData" -DataTable $out -Force
|
Invoke-SQLiteBulkCopy -DataSource $PathToDB_Copy -Table "FolderData" -DataTable $out -Force
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$DBConnect.Close()
|
|
||||||
}
|
}
|
||||||
|
$DBConnect.Close()
|
||||||
|
|
||||||
Write-Progress @CurentLoopProgress -Completed
|
Write-Progress @CurentLoopProgress -Completed
|
||||||
}
|
}
|
||||||
Write-Progress @ServerProgress -Completed
|
Write-Progress @ServerProgress -Completed
|
||||||
|
Loading…
Reference in New Issue
Block a user