From 59bab0c703058cb4d5b4b4e230aff6d3f0263de4 Mon Sep 17 00:00:00 2001 From: eeckert Date: Mon, 2 Oct 2023 16:06:05 -0600 Subject: [PATCH 1/9] New strategy...dropping to Folder Level --- Generate Egnyte Export-old.sql | 24 ++++++++++++++++++++++++ Generate Egnyte Export.sql | 25 +------------------------ Get-ProjectFolders.ps1 | 7 +++---- 3 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 Generate Egnyte Export-old.sql diff --git a/Generate Egnyte Export-old.sql b/Generate Egnyte Export-old.sql new file mode 100644 index 0000000..769ca20 --- /dev/null +++ b/Generate Egnyte Export-old.sql @@ -0,0 +1,24 @@ +-- Generate Non-Duplicated PARENT FOLDER List +DROP TABLE DataInventory; +CREATE TABLE DataInventory AS +Select * from ( + SELECT SERVER, + REPLACE( + Parent, + "X:\","\\mpe.ca\datadrive\") AS UNCPath, + REPLACE(REPLACE(Parent,("\\mpe.ca\datadrive\" || Server),"/Shared/N-Data"),"\","/") AS EgnytePath, + sum(FileCount) as FileCount, Sum(FileSize) as FileSize, 'Parent' as Source, Status from FolderData + Where Parent in ( + SELECT Parent FROM NonDupParent + ) + AND FolderData.fld_MigrationID IS NULL +GROUP by UNCPath +) +union +SELECT SERVER, + REPLACE(PATH,"X:\","\\mpe.ca\datadrive\") AS UNCPath, + REPLACE(REPLACE(PATH,("\\mpe.ca\datadrive\" || Server),"/Shared/N-Data"),"\","/") AS EgnytePath, + FileCount, FileSize, 'Project' as Source, Status from FolderData +Where FolderData.Project in ( + SELECT Project FROM NonDupProject) +AND FolderData.fld_MigrationID IS NULL; \ No newline at end of file diff --git a/Generate Egnyte Export.sql b/Generate Egnyte Export.sql index 769ca20..c4a0f39 100644 --- a/Generate Egnyte Export.sql +++ b/Generate Egnyte Export.sql @@ -1,24 +1 @@ --- Generate Non-Duplicated PARENT FOLDER List -DROP TABLE DataInventory; -CREATE TABLE DataInventory AS -Select * from ( - SELECT SERVER, - REPLACE( - Parent, - "X:\","\\mpe.ca\datadrive\") AS UNCPath, - REPLACE(REPLACE(Parent,("\\mpe.ca\datadrive\" || Server),"/Shared/N-Data"),"\","/") AS EgnytePath, - sum(FileCount) as FileCount, Sum(FileSize) as FileSize, 'Parent' as Source, Status from FolderData - Where Parent in ( - SELECT Parent FROM NonDupParent - ) - AND FolderData.fld_MigrationID IS NULL -GROUP by UNCPath -) -union -SELECT SERVER, - REPLACE(PATH,"X:\","\\mpe.ca\datadrive\") AS UNCPath, - REPLACE(REPLACE(PATH,("\\mpe.ca\datadrive\" || Server),"/Shared/N-Data"),"\","/") AS EgnytePath, - FileCount, FileSize, 'Project' as Source, Status from FolderData -Where FolderData.Project in ( - SELECT Project FROM NonDupProject) -AND FolderData.fld_MigrationID IS NULL; \ No newline at end of file +DROP TABLE IF EXISTS DataInventory; \ No newline at end of file diff --git a/Get-ProjectFolders.ps1 b/Get-ProjectFolders.ps1 index ae91961..fdb5ea3 100644 --- a/Get-ProjectFolders.ps1 +++ b/Get-ProjectFolders.ps1 @@ -55,7 +55,7 @@ $OfficeList | ForEach-Object -parallel { $XDrivePath = $_.FullName # Write-Host "Processing " $_.FullName -ForegroundColor Green - $ProjectFolders = get-childitem $_.FullName -Directory -Depth 2 | Where-Object FullName -Match $USING:ProjectRegex + $ProjectFolders = get-childitem $_.FullName -Directory -Depth 1 | Where-Object FullName -Match $USING:ProjectRegex # $ProjectFolders now contains all folders down to the 3rd level of project number - for Example, 1234-567-001. We can now generate a project number for the output file. # We need to get a file count for each "last" folder - IE, 001 in the example 1234-567-001. @@ -108,7 +108,7 @@ $OfficeList | ForEach-Object -parallel { $Path = $Path.Replace("X:\", "\\mpe.ca\datadrive\") $projectnumber = $result.tostring() $DBConnect = New-SqliteConnection -DataSource $PathToDB_Copy - $Query = "Select Project,fld_LastRefresh FROM FolderData where Project = '$ProjectNumber' AND Server = '$Server' AND Path = `"$Path`";" + $Query = "Select Project,fld_LastRefresh FROM FolderData where Server = '$Server' AND Path = `"$Path`";" $sql_result = Invoke-SqliteQuery -DataSource $PathToDB_Copy -Query $Query @@ -123,7 +123,7 @@ $OfficeList | ForEach-Object -parallel { 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`"" + $Query = "Delete from FolderData WHERE Server = '$Server' AND Path = `"$Path`"" Invoke-SqliteQuery -DataSource $PathToDB_Copy -Query $Query @@ -146,7 +146,6 @@ $OfficeList | ForEach-Object -parallel { $out = [PSCustomObject]@{ Server = $Server - Project = $ProjectNumber.ToString() Parent = $folder_Parent Path = $Path FileCount = $folder_FileCount From d5219e90f4fa7596473626c056adda26bb879f82 Mon Sep 17 00:00:00 2001 From: eeckert Date: Mon, 2 Oct 2023 16:08:58 -0600 Subject: [PATCH 2/9] remove last reference to Project --- Get-ProjectFolders.ps1 | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/Get-ProjectFolders.ps1 b/Get-ProjectFolders.ps1 index fdb5ea3..6b2be4a 100644 --- a/Get-ProjectFolders.ps1 +++ b/Get-ProjectFolders.ps1 @@ -108,11 +108,11 @@ $OfficeList | ForEach-Object -parallel { $Path = $Path.Replace("X:\", "\\mpe.ca\datadrive\") $projectnumber = $result.tostring() $DBConnect = New-SqliteConnection -DataSource $PathToDB_Copy - $Query = "Select Project,fld_LastRefresh FROM FolderData where Server = '$Server' AND Path = `"$Path`";" + $Query = "Select fld_LastRefresh FROM FolderData where Server = '$Server' AND Path = `"$Path`";" $sql_result = Invoke-SqliteQuery -DataSource $PathToDB_Copy -Query $Query - if (($sql_result.project -eq $null) -or ($sql_result.fld_LastRefresh -le (Get-Date).AddDays($RefreshDays).ToShortDateString())) { + if (($sql_result.fld_LastRefresh -le (Get-Date).AddDays($RefreshDays).ToShortDateString())) { $CurentLoopProgress = @{ ID = $JobID Activity = "Loading Telemetry for " + $_.FullName @@ -120,15 +120,7 @@ $OfficeList | ForEach-Object -parallel { } 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 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 $folder_Parent = $result3.value.replace("'", "`'") #SQL Formatting From f507c7674060fab6b0e619a2f9d357fdf9dcedeb Mon Sep 17 00:00:00 2001 From: eeckert Date: Mon, 2 Oct 2023 16:17:35 -0600 Subject: [PATCH 3/9] 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 From 65dac21d09986410dfcb41f0cbe07305afac60f8 Mon Sep 17 00:00:00 2001 From: eeckert Date: Mon, 2 Oct 2023 16:20:36 -0600 Subject: [PATCH 4/9] remove duplicate project SQL --- Get-ProjectFolders.ps1 | 72 +++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/Get-ProjectFolders.ps1 b/Get-ProjectFolders.ps1 index f53d999..3495f08 100644 --- a/Get-ProjectFolders.ps1 +++ b/Get-ProjectFolders.ps1 @@ -203,61 +203,61 @@ Invoke-SqliteQuery -DataSource $PathToDB -Query $Query ## Kick off GenTables -$SQLFile_to_Run = $PSScriptRoot + '\GenTables.sql' -Invoke-SqliteQuery -DataSource $PathToDB -InputFile $SQLFile_to_Run -$SQLFile_to_Run = $PSScriptRoot + '\DuplicatePairing.sql' -Invoke-SqliteQuery -DataSource $PathToDB -InputFile $SQLFile_to_Run +# $SQLFile_to_Run = $PSScriptRoot + '\GenTables.sql' +# Invoke-SqliteQuery -DataSource $PathToDB -InputFile $SQLFile_to_Run +# $SQLFile_to_Run = $PSScriptRoot + '\DuplicatePairing.sql' +# Invoke-SqliteQuery -DataSource $PathToDB -InputFile $SQLFile_to_Run $DBConnect = New-SqliteConnection -DataSource $PathToDB -foreach ($office in $OfficeList) { - $OfficeServer = $office.Name +# foreach ($office in $OfficeList) { +# $OfficeServer = $office.Name - $Query = "select * from OfficeDuplicates where Server = '$OfficeServer';" - $sql_result = Invoke-SqliteQuery -DataSource $PathToDB -Query $Query +# $Query = "select * from OfficeDuplicates where Server = '$OfficeServer';" +# $sql_result = Invoke-SqliteQuery -DataSource $PathToDB -Query $Query - if ($sql_result) { - $OutFile = $OutputFolder + "\$OfficeServer Duplicates.xlsx" - Remove-Item -Path $OutFile -Force - $sql_result | Export-Excel -Path $OutFile -AutoFilter +# if ($sql_result) { +# $OutFile = $OutputFolder + "\$OfficeServer Duplicates.xlsx" +# Remove-Item -Path $OutFile -Force +# $sql_result | Export-Excel -Path $OutFile -AutoFilter - } -} +# } +# } # Generate MPE All Xlsx -$Query = "select * from OfficeDuplicates;" -$sql_result = Invoke-SqliteQuery -DataSource $PathToDB -Query $Query +# $Query = "select * from OfficeDuplicates;" +# $sql_result = Invoke-SqliteQuery -DataSource $PathToDB -Query $Query -if ($sql_result) { - $OutFile = $OutputFolder + "\MPE All Duplicates.xlsx" - Remove-Item -Path $OutFile -Force - $sql_result | Export-Excel -Path $OutFile -AutoFilter +# if ($sql_result) { +# $OutFile = $OutputFolder + "\MPE All Duplicates.xlsx" +# Remove-Item -Path $OutFile -Force +# $sql_result | Export-Excel -Path $OutFile -AutoFilter -} +# } # Generate Parent Non-Duplicates -$Query = "select * from NonDupParent;" -$sql_result = Invoke-SqliteQuery -DataSource $PathToDB -Query $Query +# $Query = "select * from NonDupParent;" +# $sql_result = Invoke-SqliteQuery -DataSource $PathToDB -Query $Query -if ($sql_result) { - $OutFile = $OutputFolder + "\MPE Non-Duplicates - Parent Folders.xlsx" - Remove-Item -Path $OutFile -Force - $sql_result | Export-Excel -Path $OutFile -AutoFilter +# if ($sql_result) { +# $OutFile = $OutputFolder + "\MPE Non-Duplicates - Parent Folders.xlsx" +# Remove-Item -Path $OutFile -Force +# $sql_result | Export-Excel -Path $OutFile -AutoFilter -} +# } -# Generate Project Non-Duplicates +# # Generate Project Non-Duplicates -$Query = "select * from NonDupProject where Path NOT IN (select Path from NonDupParent);" -$sql_result = Invoke-SqliteQuery -DataSource $PathToDB -Query $Query +# $Query = "select * from NonDupProject where Path NOT IN (select Path from NonDupParent);" +# $sql_result = Invoke-SqliteQuery -DataSource $PathToDB -Query $Query -if ($sql_result) { - $OutFile = $OutputFolder + "\MPE Non-Duplicates - Project Folders.xlsx" - Remove-Item -Path $OutFile -Force - $sql_result | Export-Excel -Path $OutFile -AutoFilter +# if ($sql_result) { +# $OutFile = $OutputFolder + "\MPE Non-Duplicates - Project Folders.xlsx" +# Remove-Item -Path $OutFile -Force +# $sql_result | Export-Excel -Path $OutFile -AutoFilter -} +# } ## Generate Egnyte Data Inventory Sheet From e830742918195e9dc3c17f6315e46d5081f951b0 Mon Sep 17 00:00:00 2001 From: eeckert Date: Mon, 2 Oct 2023 16:44:07 -0600 Subject: [PATCH 5/9] I am not proud... --- Generate Egnyte Export.sql | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Generate Egnyte Export.sql b/Generate Egnyte Export.sql index c4a0f39..cff1604 100644 --- a/Generate Egnyte Export.sql +++ b/Generate Egnyte Export.sql @@ -1 +1,12 @@ -DROP TABLE IF EXISTS DataInventory; \ No newline at end of file +DROP TABLE IF EXISTS DataInventory; +Select * from ( + SELECT SERVER, + REPLACE( + Parent, + "X:\","\\mpe.ca\datadrive\") AS UNCPath, + REPLACE(REPLACE(REPLACE(Parent,("\\mpe.ca\datadrive\" || Server),REPLACE("/Shared/N-Data/" || Server || "_/","_/","_")),"\","/"),"_/","_") AS EgnytePath, + sum(FileCount) as FileCount, Sum(FileSize) as FileSize, Status from FolderData + WHERE FolderData.fld_MigrationID IS NULL +GROUP by UNCPath +ORDER by UNCPath +); From 502e9ea0fd1925f42b405ce00cd006c724f2e771 Mon Sep 17 00:00:00 2001 From: eeckert Date: Tue, 3 Oct 2023 13:11:01 -0600 Subject: [PATCH 6/9] create new table --- Generate Egnyte Export.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Generate Egnyte Export.sql b/Generate Egnyte Export.sql index cff1604..6f8b45b 100644 --- a/Generate Egnyte Export.sql +++ b/Generate Egnyte Export.sql @@ -1,4 +1,6 @@ DROP TABLE IF EXISTS DataInventory; + +create table DataInventory as Select * from ( SELECT SERVER, REPLACE( From dee9406e975f876fd663b04eb37208cbf9fe5a73 Mon Sep 17 00:00:00 2001 From: eeckert Date: Tue, 3 Oct 2023 13:15:44 -0600 Subject: [PATCH 7/9] adjust SQL --- Get-ProjectFolders.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Get-ProjectFolders.ps1 b/Get-ProjectFolders.ps1 index 3495f08..8f0fd54 100644 --- a/Get-ProjectFolders.ps1 +++ b/Get-ProjectFolders.ps1 @@ -271,7 +271,7 @@ catch { } $SQLFile_to_Run = $PSScriptRoot + '\Generate Egnyte Export.sql' Invoke-SqliteQuery -DataSource $PathToDB -InputFile $SQLFile_to_Run -$EgnyteExport = Invoke-SqliteQuery -DataSource $PathToDB -Query "Select Server,UNCPath,EgnytePath,FileCount,FileSize,Source from DataInventory" +$EgnyteExport = Invoke-SqliteQuery -DataSource $PathToDB -Query "Select Server,UNCPath,EgnytePath,FileCount,FileSize,Status from DataInventory" if ($EgnyteExport) { From b56a41f5ecf8a34a3e2f0ad5652467ee5d658de5 Mon Sep 17 00:00:00 2001 From: eeckert Date: Tue, 3 Oct 2023 13:31:08 -0600 Subject: [PATCH 8/9] update Regex for fodler detection. --- Get-ProjectFolders.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Get-ProjectFolders.ps1 b/Get-ProjectFolders.ps1 index 8f0fd54..e10a440 100644 --- a/Get-ProjectFolders.ps1 +++ b/Get-ProjectFolders.ps1 @@ -27,7 +27,7 @@ $PAth_To_Migration_Status = "M:\00 - Egnyte PS Data Inventory\Migration_status\M $PathToDB = "M:\IT\Egnyte\DuplicateFiles\WorkingRun\Dedupe.SQLite" $OutputFolder = "M:\IT\Egnyte\DuplicateFiles\WorkingRun\Output" $BaseDrive = 'X:\' -$ProjectRegex = '^X:\\[A-Z]{2}\W\d{2}\\\d{2}' +$ProjectRegex = '^X:\\[A-Z]{2}\W\d+' $OfficeList = Get-ChildItem -Path $BaseDrive -Directory -Depth 0 if ($Refresh) { From 374c91715b82421397011ff04aa16adecefedeba Mon Sep 17 00:00:00 2001 From: eeckert Date: Wed, 4 Oct 2023 14:56:27 -0600 Subject: [PATCH 9/9] Adjust Output for new method. --- Get-ProjectFolders.ps1 | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/Get-ProjectFolders.ps1 b/Get-ProjectFolders.ps1 index e10a440..ee2c8da 100644 --- a/Get-ProjectFolders.ps1 +++ b/Get-ProjectFolders.ps1 @@ -27,7 +27,7 @@ $PAth_To_Migration_Status = "M:\00 - Egnyte PS Data Inventory\Migration_status\M $PathToDB = "M:\IT\Egnyte\DuplicateFiles\WorkingRun\Dedupe.SQLite" $OutputFolder = "M:\IT\Egnyte\DuplicateFiles\WorkingRun\Output" $BaseDrive = 'X:\' -$ProjectRegex = '^X:\\[A-Z]{2}\W\d+' +$ProjectRegex = '^X:\\[A-Z]{2}\W[a-zA-Z0-9 ]*\\' $OfficeList = Get-ChildItem -Path $BaseDrive -Directory -Depth 0 if ($Refresh) { @@ -149,7 +149,7 @@ server,path,path2,etc,status,OriginalServer=RD,OriginalProject=ProjectNumber #> - +$DBConnect = New-SqliteConnection -DataSource $PathToDB <# Get Migration Status CREATE TABLE "MigrationStatus" ( "MigrationID" TEXT NOT NULL UNIQUE, @@ -208,7 +208,7 @@ Invoke-SqliteQuery -DataSource $PathToDB -Query $Query # $SQLFile_to_Run = $PSScriptRoot + '\DuplicatePairing.sql' # Invoke-SqliteQuery -DataSource $PathToDB -InputFile $SQLFile_to_Run -$DBConnect = New-SqliteConnection -DataSource $PathToDB + # foreach ($office in $OfficeList) { # $OfficeServer = $office.Name @@ -278,6 +278,32 @@ if ($EgnyteExport) { $EgnyteExport | Export-Excel -Path $OutFile -AutoFilter } +$OutFile = $OutputFolder + "\FULL MPE Data Inventory " + (Get-Date -Format FileDate) + ".xlsx" +try { + + Remove-Item -Path $OutFile -Force -ErrorAction SilentlyContinue +} +catch { + <#Do this if a terminating exception happens#> +} +$Query = 'Select * from ( + SELECT SERVER, + REPLACE( + Parent, + "X:\","\\mpe.ca\datadrive\") AS UNCPath, + REPLACE(REPLACE(REPLACE(Parent,("\\mpe.ca\datadrive\" || Server),REPLACE("/Shared/N-Data/" || Server || "_/","_/","_")),"\","/"),"_/","_") AS EgnytePath, + sum(FileCount) as FileCount, Sum(FileSize) as FileSize, Status, fld_MigrationID,MigrationName from FolderData + LEFT JOIN MigrationStatus on FolderData.fld_MigrationID = MigrationID +-- WHERE FolderData.fld_MigrationID IS NULL +GROUP by UNCPath +ORDER by UNCPath +);' +$FullEgnyteExport = Invoke-SqliteQuery -DataSource $PathToDB -Query $Query +if ($FullEgnyteExport) { + + $FullEgnyteExport | Export-Excel -Path $OutFile -AutoFilter +} + $DBConnect.Close()