fixed single quote escaping!

This commit is contained in:
Erik Eckert 2023-09-27 14:20:31 -06:00
parent f02f0d1d42
commit 58de9f534f

View File

@ -22,7 +22,8 @@ param (
#refresh all data - causes the DB to be wiped clean and all file folders to be re-analyzed. #refresh all data - causes the DB to be wiped clean and all file folders to be re-analyzed.
$Path_To_Working_copy = "M:\00 - Egnyte PS Data Inventory\Output\MPE Data Inventory - Working.xlsx"
$PAth_To_Migration_Status = "M:\00 - Egnyte PS Data Inventory\Migration_status\Migration_Health_stat_MPE.xlsx"
$PathToDB = "M:\IT\Egnyte\DuplicateFiles\WorkingRun\Dedupe.SQLite" $PathToDB = "M:\IT\Egnyte\DuplicateFiles\WorkingRun\Dedupe.SQLite"
$OutputFolder = "M:\IT\Egnyte\DuplicateFiles\WorkingRun\Output" $OutputFolder = "M:\IT\Egnyte\DuplicateFiles\WorkingRun\Output"
$BaseDrive = 'X:\' $BaseDrive = 'X:\'
@ -101,7 +102,7 @@ $OfficeList | ForEach-Object -parallel {
} }
elseif ($result.Length -ge 5) { elseif ($result.Length -ge 5) {
$Server = $_.FullName.Substring(1, 4) -replace (':|\\', '') $Server = $_.FullName.Substring(1, 4) -replace (':|\\', '')
$Path = $_.FullName.Replace("'", "''") #SQL Formatted Path $Path = $_.FullName.Replace("'", "`'") #SQL Formatted Path
$projectnumber = $result.tostring() $projectnumber = $result.tostring()
$DBConnect = New-SqliteConnection -DataSource $PathToDB_Copy $DBConnect = New-SqliteConnection -DataSource $PathToDB_Copy
$Query = "Select Project FROM FolderData where Project = '$ProjectNumber' AND Server = '$Server' AND Path = '$Path';" $Query = "Select Project FROM FolderData where Project = '$ProjectNumber' AND Server = '$Server' AND Path = '$Path';"
@ -119,7 +120,7 @@ $OfficeList | ForEach-Object -parallel {
$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_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
@ -140,6 +141,7 @@ $OfficeList | ForEach-Object -parallel {
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
} | Out-DataTable } | Out-DataTable
Invoke-SQLiteBulkCopy -DataSource $PathToDB_Copy -Table "FolderData" -DataTable $out -Force Invoke-SQLiteBulkCopy -DataSource $PathToDB_Copy -Table "FolderData" -DataTable $out -Force
@ -161,6 +163,19 @@ $ServerProgress = @{
} }
Write-Progress @ServerProgress Write-Progress @ServerProgress
<#
TODO Grab data from Egnyte Working Copy to re-incorporate into our DB. This will allow us to mark data as "in progress", and thus filter it out from future data inventory updates.
TODO Need to update Working Copy sheet to contain Project Number and Server for unique keys, and add antoher column for Egnyte Friendly Server Names to match the Migration Server names.
IE,
server,path,path2,etc,status,OriginalServer=RD,OriginalProject=ProjectNumber
#>
$MigrationStatus_import = Import-Excel -Path $PAth_To_Migration_Status -WorksheetName "MPE Migration Tracker" -StartRow 2 | Out-DataTable
Invoke-SQLiteBulkCopy -DataSource $PathToDB -Table "MigrationStatus" -DataTable $MigrationStatus_import -Force -ConflictClause Replace
## Kick off GenTables ## Kick off GenTables