diff --git a/Get-ProjectFolders.ps1 b/Get-ProjectFolders.ps1 index 4ba6da5..616d6b5 100644 --- a/Get-ProjectFolders.ps1 +++ b/Get-ProjectFolders.ps1 @@ -103,6 +103,7 @@ $OfficeList | ForEach-Object -parallel { elseif ($result.Length -ge 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 Project FROM FolderData where Project = '$ProjectNumber' AND Server = '$Server' AND Path = `"$Path`";" @@ -121,6 +122,7 @@ $OfficeList | ForEach-Object -parallel { $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 @@ -172,8 +174,44 @@ 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 +<# Get Migration Status +CREATE TABLE "MigrationStatus" ( + "MigrationID" TEXT NOT NULL UNIQUE, + "MigrationName" TEXT, + "MigrationFolderSource" TEXT, + "MigrationFolderDestination" TEXT, + "MigrationStatus" INTEGER, + PRIMARY KEY("MigrationID") +); + +#> + +$MigrationStatus_import = Import-Excel -Path $PAth_To_Migration_Status -WorksheetName "MPE Migration Tracker" -StartRow 2 +foreach ($status in $MigrationStatus_import) { + $SQLSourcePath = $status.'Source Path'.replace("'", "`'") #SQL Formatting + $SQLDestPath = $status.'Destination Path'.replace("'", "`'") #SQL Formatting + $SQLMigrationID = $status.'Migration ID' + $SQLMigrationName = $status.'Migration Name' + $SQLMigrationStatus = $status.'Current State' + + # TODO Add code to ensure there's a trailing slash on Source and Dest paths (consistency) + + $Query = "Select * from MigrationStatus WHERE MigrationID = `'$SQLMigrationID`'" + $Test = Invoke-SqliteQuery -DataSource $PathToDB -Query $Query + + if ($test) { + $Query = "UPDATE MigrationStatus SET MigrationStatus = '$SQLMigrationStatus' WHERE MigrationID = '$SQLMigrationID'" + Invoke-SqliteQuery -DataSource $PathToDB -Query $Query + } + else { + $Query = "INSERT INTO MigrationStatus VALUES ('$SQLMigrationID','$SQLMigrationName',`'$SQLSourcePath`',`'$SQLDestPath`','$SQLMigrationStatus')" + Invoke-SqliteQuery -DataSource $PathToDB -Query $Query + } + + +} + +