missed one
This commit is contained in:
parent
d5219e90f4
commit
f507c76740
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user