Lotus Notes to Shareflex QMS, via SQL using PNP Powershell
This blog post shows how to migrate Lotus Notes database content to its final destination: a SharePoint Shareflex application (in this example, Shareflex QMS). Your Notes database and Shareflex setup will differ, so some adjustments are required, but this guide will get you started.
Lift and shift the IBM Notes content to SQL
For this blog post, we created a small proof-of-concept (PoC) Lotus Notes application to hold the sample data. The app is not from a real customer project, but specifically built to demonstrate the migration approach in a clear and controlled way. The screenshots below show the structure and example content used in this PoC.
First, the Notes database is migrated to SQL using the Lialis LNExtract tool. LNExtract performs a lift-and-shift migration of the Notes content to SQL, including all documents, all fields, and all rich text content. After the initial migration, daily changes in the Notes database can also be migrated automatically to SQL, keeping SQL in sync with Notes during the transition period.
Transform SQL content into Shareflex QMS documents
Once the Notes content is available in SQL, the next step becomes much easier. From SQL, the data can be migrated into the Shareflex QMS structure on SharePoint Online.
The images below show the Notes document above after it was migrated to Shareflex QMS.
Azure AD application
Before we can run the PnP PowerShell migration, we first need to register an Azure AD application for authentication. This app is used by the script to securely connect to SharePoint Online and perform the migration without using interactive user credentials.
In this example, we create the app using PnP PowerShell:
|
1 |
Register-PnPAzureADApp -ApplicationName “Lialis SPO Notes Migration Tool 1” -Tenant lialis.com -OutPath c:\temp -CertificatePassword (ConvertTo-SecureString -String “pipelinerpassword” -AsPlainText -Force) -devicelogin |
PnP PowerShell script we used
The script connects to the SQL table, reads the first entry, exports the attachments from MIME using MimeKit, and creates the items in SharePoint so they are presented properly in the Shareflex interface.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 |
#text file logging on users PC **************************************************** $LogFolder = "E:\NotesSQLShareflex\Logs" if (!(Test-Path $LogFolder)) { New-Item -ItemType Directory -Path $LogFolder | Out-Null } $LogDateTime = Get-Date -Format "yyyy-MM-dd_HH-mm-ss" $LogFile = Join-Path $LogFolder "sqltoshareflex_$LogDateTime.txt" New-Item -ItemType File -Path $LogFile -Force | Out-Null function Write-Log { param( [string]$Message ) $LogLine = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - $Message" Add-Content -Path $LogFile -Value $LogLine Write-Host $LogLine } # Gets a text value from a SQL row by column name, trims spaces, removes surrounding quotes, and returns $null when empty function Get-SQLStringValue { param( [System.Data.DataRow]$Row, [string]$ColumnName ) if (-not $Row.Table.Columns.Contains($ColumnName)) { return $null } if ($null -eq $Row[$ColumnName]) { return $null } $v = $Row[$ColumnName].ToString().Trim() if ([string]::IsNullOrWhiteSpace($v)) { return $null } while ($v.StartsWith('"') -and $v.EndsWith('"') -and $v.Length -ge 2) { $v = $v.Substring(1, $v.Length - 2).Trim() } if ([string]::IsNullOrWhiteSpace($v)) { return $null } return $v } # Gets a date value from a SQL row by column name, trims spaces, removes surrounding quotes, converts it to datetime, and returns $null when conversion fails function Get-SQLDateValue { param( [System.Data.DataRow]$Row, [string]$ColumnName ) if (-not $Row.Table.Columns.Contains($ColumnName)) { return $null } if ($null -eq $Row[$ColumnName]) { return $null } $raw = $Row[$ColumnName].ToString().Trim() if ([string]::IsNullOrWhiteSpace($raw)) { return $null } while ($raw.StartsWith('"') -and $raw.EndsWith('"') -and $raw.Length -ge 2) { $raw = $raw.Substring(1, $raw.Length - 2).Trim() } if ([string]::IsNullOrWhiteSpace($raw)) { return $null } try { return [datetime]::Parse($raw) } catch { return $null } } # Cleans a SQL user value by trimming spaces, removing surrounding quotes, and removing the trailing /Lialis part from Notes-style usernames function Clean-SQLUserValue { param( [string]$Value ) if ([string]::IsNullOrWhiteSpace($Value)) { return $null } $CleanValue = $Value.Trim() while ($CleanValue.StartsWith('"') -and $CleanValue.EndsWith('"') -and $CleanValue.Length -ge 2) { $CleanValue = $CleanValue.Substring(1, $CleanValue.Length - 2).Trim() } if ($CleanValue -like "*/Lialis") { $CleanValue = $CleanValue.Substring(0, $CleanValue.Length - 7).Trim() } if ([string]::IsNullOrWhiteSpace($CleanValue)) { return $null } return $CleanValue } # Reads one SQL record by Notes universal id, saves the MIME content to disk, extracts text and attachments, and stores them in a folder named with the universal id function Export-MimeSqlDocument { param( [string]$SQLUniversalId ) Add-Type -Path $MimeKitDllPath if ([string]::IsNullOrWhiteSpace($SQLUniversalId)) { Write-Host "SQLUniversalId is empty" return } if (!(Test-Path $MimeOutputRoot)) { New-Item -ItemType Directory -Path $MimeOutputRoot | Out-Null } $Query = "SELECT universalid, ValidDocuments FROM [$SQLSchema].[$SQLTable] WHERE universalid = @universalid" $conn = New-Object System.Data.SqlClient.SqlConnection $conn.ConnectionString = "Server=$SQLServer;Database=$SQLDatabase;User ID=$SQLUsername;Password=$SQLPassword;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" try { $conn.Open() $cmd = $conn.CreateCommand() $cmd.CommandText = $Query $null = $cmd.Parameters.Add("@universalid", [System.Data.SqlDbType]::NChar, 32) $cmd.Parameters["@universalid"].Value = $SQLUniversalId $reader = $cmd.ExecuteReader() if ($reader.Read()) { $id = $reader["universalid"].ToString().Trim() $desc = $reader["ValidDocuments"] $folder = Join-Path $MimeOutputRoot $id if (!(Test-Path $folder)) { New-Item -ItemType Directory -Path $folder | Out-Null } $emlPath = Join-Path $folder "message.eml" $textFile = Join-Path $folder "message.txt" $imageFolder = Join-Path $folder "images" if (!(Test-Path $imageFolder)) { New-Item -ItemType Directory -Path $imageFolder | Out-Null } try { [System.IO.File]::WriteAllText($emlPath, $desc) Write-Host "EML opgeslagen: $emlPath" $stream = [System.IO.File]::OpenRead($emlPath) $email = [MimeKit.MimeMessage]::Load($stream) $stream.Close() $emailBody = $email.TextBody $emailBody | Out-File $textFile -Encoding UTF8 Write-Host "Text content opgeslagen: $textFile" foreach ($attachment in $email.Attachments) { $fileName = $attachment.ContentDisposition?.FileName if (-not $fileName) { $fileName = $attachment.ContentType.Name } if (-not $fileName) { continue } $attachmentPath = if ($fileName -match "\.jpg$|\.png$|\.gif$|\.jpeg$") { Join-Path $imageFolder $fileName } else { Join-Path $folder $fileName } $fileStream = [System.IO.File]::Create($attachmentPath) $attachment.Content.DecodeTo($fileStream) $fileStream.Close() Write-Host "Attachment saved: $attachmentPath" } } catch { Write-Host ("Error processing {0}: {1}" -f $id, $_.Exception.Message) } } else { Write-Host "No SQL row found for universalid $SQLUniversalId" } $reader.Close() } finally { if ($conn.State -eq [System.Data.ConnectionState]::Open) { $conn.Close() } } } #SQL connection to retrieve the Notes documents **************************************************** $SQLServer = "tcp:azuresqlserver.database.windows.net,1433" $SQLDatabase = "shareflex_qms" $SQLUsername = "sa username goes here" $SQLPassword = "sa password goes here" $SQLTable = "validdocument" $SQLSchema = "dbo" # SQL Mime settings **************************************************** $MimeKitDllPath = "E:\mimekit\lib\netstandard2.0\MimeKit.dll" $MimeOutputRoot = "E:\NotesSQLShareflex\SQLMIMIEXPORT\" #Shareflex SharePoint connections and settings **************************************************** #Valid Documents $ShareflexValidDocs = "https://clienttenantname.sharepoint.com/sites/ShareflexQualityDocuments" $SPODocLibRoot = "/sites/ShareflexQualityDocuments/Documents" $SPOContentTypeName = "QM Document" #Attachments Valid $ShareflexWorkspaceSite = "https://clienttenantname.sharepoint.com/sites/ShareflexQualityDocuments/Workspace" $SPOAttachmentLibRoot = "/sites/ShareflexQualityDocuments/Workspace/AttachmentsValid" $SPOAttachmentContentTypeName = "QM Attachment" #SharePoint Authentication $clientId = "app id goes here" $tenantid = "tenant id goes here" $pfxpath = "E:\NotesSQLShareflex\appid001shareflexqmssql.pfx" $certpassword = "app cer password goes here" #Connect to the Shareflex Valid document library in Sharepoint **************************************************** Write-Host "************* Connecting to SharePoint Online holding Shareflex QMS *************" Write-log "************* Connecting to SharePoint Online holding Shareflex QMS *************" Connect-PnPOnline ` -Url $ShareflexValidDocs ` -ClientId $clientId ` -CertificatePath $pfxpath ` -CertificatePassword (ConvertTo-SecureString -AsPlainText $certpassword -Force) ` -Tenant $tenantid ` -WarningAction Ignore # **************************************** # Read all SQL items, report metadata, then create Shareflex items using first docx from mime export # **************************************** $CarryOutSQLToShareflexTest = (Read-Host "Read all SQL rows and create Shareflex test items? (yes/no)").ToLower().Trim() if ($CarryOutSQLToShareflexTest -eq "y") { Write-Host "************* Reading SQL rows from $SQLSchema.$SQLTable *************" Write-Log "************* Reading SQL rows from $SQLSchema.$SQLTable *************" $SQLConnection = New-Object System.Data.SqlClient.SqlConnection $SQLConnection.ConnectionString = "Server=$SQLServer;Database=$SQLDatabase;User ID=$SQLUsername;Password=$SQLPassword;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" try { $SQLConnection.Open() $SQLQuery = @" SELECT * FROM [$SQLSchema].[$SQLTable] ORDER BY [_created] ASC "@ $SQLCommand = $SQLConnection.CreateCommand() $SQLCommand.CommandText = $SQLQuery $SQLAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $SQLCommand $SQLDataTable = New-Object System.Data.DataTable [void]$SQLAdapter.Fill($SQLDataTable) if ($SQLDataTable.Rows.Count -eq 0) { Write-Host "No SQL rows found in $SQLSchema.$SQLTable" Write-Log "No SQL rows found in $SQLSchema.$SQLTable" } else { Write-Host "Total SQL rows found: $($SQLDataTable.Rows.Count)" Write-Log "Total SQL rows found: $($SQLDataTable.Rows.Count)" $RowCounter = 0 foreach ($SQLRow in $SQLDataTable.Rows) { $RowCounter++ #Document $SQLDocTitle = Get-SQLStringValue -Row $SQLRow -ColumnName "doctitle" $SQLDocNumber = Get-SQLStringValue -Row $SQLRow -ColumnName "docnumber" $SQLDocType = Get-SQLStringValue -Row $SQLRow -ColumnName "doctype" $SQLTemplateNo = Get-SQLStringValue -Row $SQLRow -ColumnName "doctemplatenumber" $SQLTemplateTitle = Get-SQLStringValue -Row $SQLRow -ColumnName "doctemplatetitle" $SQLEditor = Clean-SQLUserValue -Value (Get-SQLStringValue -Row $SQLRow -ColumnName "editor") $SQLDocLanguage = Get-SQLStringValue -Row $SQLRow -ColumnName "doclanguage" $SQLNotificationUsers = Clean-SQLUserValue -Value (Get-SQLStringValue -Row $SQLRow -ColumnName "docnotificationusers") #Revision $SQLRevisionNo = Get-SQLStringValue -Row $SQLRow -ColumnName "docrevisionnumber" $SQLRevisionReason = Get-SQLStringValue -Row $SQLRow -ColumnName "docrevisionreason" $SQLRevisionChange = Get-SQLStringValue -Row $SQLRow -ColumnName "docrevisionchange" $SQLValidFrom = Get-SQLDateValue -Row $SQLRow -ColumnName "docvalidfrom" $SQLValidUntil = Get-SQLDateValue -Row $SQLRow -ColumnName "docvaliduntil" #Categories $SQLClient = Get-SQLStringValue -Row $SQLRow -ColumnName "doccategoryclient" $SQLProcessGroup = Get-SQLStringValue -Row $SQLRow -ColumnName "doccategoryprocessgroup" $SQLDepartment = Get-SQLStringValue -Row $SQLRow -ColumnName "doccategorydepartment" $SQLProcess2 = Get-SQLStringValue -Row $SQLRow -ColumnName "doccategoryprocess" $SQLStandard = Get-SQLStringValue -Row $SQLRow -ColumnName "doccategorystandard" $SQLSubProcess = Get-SQLStringValue -Row $SQLRow -ColumnName "doccategorysubprocess" #Approval $SQLReviewer = Clean-SQLUserValue -Value (Get-SQLStringValue -Row $SQLRow -ColumnName "docapprovalrevieweruser") $SQLApprover = Clean-SQLUserValue -Value (Get-SQLStringValue -Row $SQLRow -ColumnName "docapprovalapprovaluser") $SQLConfirmer = Clean-SQLUserValue -Value (Get-SQLStringValue -Row $SQLRow -ColumnName "docapprovalconfirmationuser") $SQLReviewResult = Get-SQLStringValue -Row $SQLRow -ColumnName "docapprovalrevieweruserresult" $SQLApprovalResult = Get-SQLStringValue -Row $SQLRow -ColumnName "docapprovalapprovaluserresult" $SQLConfirmationResult = Get-SQLStringValue -Row $SQLRow -ColumnName "docapprovalconfirmationuserresul" $SQLUniversalId = Get-SQLStringValue -Row $SQLRow -ColumnName "universalid" $SQLCreated = Get-SQLDateValue -Row $SQLRow -ColumnName "_created" $SQLModified = Get-SQLDateValue -Row $SQLRow -ColumnName "_modified" $SQLUpdatedBy = Get-SQLStringValue -Row $SQLRow -ColumnName "_updatedby" $SQLFilePath = Get-SQLStringValue -Row $SQLRow -ColumnName "_file" Write-Host "--------------------------------------------------" Write-Log "--------------------------------------------------" Write-Host "SQL values prepared for Shareflex migration" Write-Log "SQL values prepared for Shareflex migration" #Document Write-Host "Document" Write-Log "Document" Write-Host " SQLDocTitle = $SQLDocTitle" Write-Log " SQLDocTitle = $SQLDocTitle" Write-Host " SQLDocNumber = $SQLDocNumber" Write-Log " SQLDocNumber = $SQLDocNumber" Write-Host " SQLDocType = $SQLDocType" Write-Log " SQLDocType = $SQLDocType" Write-Host " SQLTemplateNo = $SQLTemplateNo" Write-Log " SQLTemplateNo = $SQLTemplateNo" Write-Host " SQLTemplateTitle = $SQLTemplateTitle" Write-Log " SQLTemplateTitle = $SQLTemplateTitle" Write-Host " SQLEditor = $SQLEditor" Write-Log " SQLEditor = $SQLEditor" Write-Host " SQLDocLanguage = $SQLDocLanguage" Write-Log " SQLDocLanguage = $SQLDocLanguage" Write-Host " SQLNotificationUsers = $SQLNotificationUsers" Write-Log " SQLNotificationUsers = $SQLNotificationUsers" #Revision Write-Host "Revision" Write-Log "Revision" Write-Host " SQLRevisionNo = $SQLRevisionNo" Write-Log " SQLRevisionNo = $SQLRevisionNo" Write-Host " SQLRevisionReason = $SQLRevisionReason" Write-Log " SQLRevisionReason = $SQLRevisionReason" Write-Host " SQLRevisionChange = $SQLRevisionChange" Write-Log " SQLRevisionChange = $SQLRevisionChange" Write-Host " SQLValidFrom = $SQLValidFrom" Write-Log " SQLValidFrom = $SQLValidFrom" Write-Host " SQLValidUntil = $SQLValidUntil" Write-Log " SQLValidUntil = $SQLValidUntil" #Categories Write-Host "Categories" Write-Log "Categories" Write-Host " SQLClient = $SQLClient" Write-Log " SQLClient = $SQLClient" Write-Host " SQLProcessGroup = $SQLProcessGroup" Write-Log " SQLProcessGroup = $SQLProcessGroup" Write-Host " SQLDepartment = $SQLDepartment" Write-Log " SQLDepartment = $SQLDepartment" Write-Host " SQLProcess2 = $SQLProcess2" Write-Log " SQLProcess2 = $SQLProcess2" Write-Host " SQLStandard = $SQLStandard" Write-Log " SQLStandard = $SQLStandard" Write-Host " SQLSubProcess = $SQLSubProcess" Write-Log " SQLSubProcess = $SQLSubProcess" #Approval Write-Host "Approval" Write-Log "Approval" Write-Host " SQLReviewer = $SQLReviewer" Write-Log " SQLReviewer = $SQLReviewer" Write-Host " SQLApprover = $SQLApprover" Write-Log " SQLApprover = $SQLApprover" Write-Host " SQLConfirmer = $SQLConfirmer" Write-Log " SQLConfirmer = $SQLConfirmer" Write-Host " SQLReviewResult = $SQLReviewResult" Write-Log " SQLReviewResult = $SQLReviewResult" Write-Host " SQLApprovalResult = $SQLApprovalResult" Write-Log " SQLApprovalResult = $SQLApprovalResult" Write-Host " SQLConfirmationResult = $SQLConfirmationResult" Write-Log " SQLConfirmationResult = $SQLConfirmationResult" #System Write-Host "System" Write-Log "System" Write-Host " SQLUniversalId = $SQLUniversalId" Write-Log " SQLUniversalId = $SQLUniversalId" Write-Host " SQLCreated = $SQLCreated" Write-Log " SQLCreated = $SQLCreated" Write-Host " SQLModified = $SQLModified" Write-Log " SQLModified = $SQLModified" Write-Host " SQLUpdatedBy = $SQLUpdatedBy" Write-Log " SQLUpdatedBy = $SQLUpdatedBy" Write-Host " SQLFilePath = $SQLFilePath" Write-Log " SQLFilePath = $SQLFilePath" Write-Host "--------------------------------------------------" Write-Log "--------------------------------------------------" if ([string]::IsNullOrWhiteSpace($SQLDocNumber)) { $SQLDocNumber = "SQL-NO-NUMBER-$RowCounter" } if ([string]::IsNullOrWhiteSpace($SQLDocTitle)) { $SQLDocTitle = $SQLDocNumber } if ([string]::IsNullOrWhiteSpace($SQLDocType)) { $SQLDocType = "Document" } if ([string]::IsNullOrWhiteSpace($SQLRevisionNo)) { $SQLRevisionNo = "1.0" } if ([string]::IsNullOrWhiteSpace($SQLClient)) { $SQLClient = "Unknown" } if ([string]::IsNullOrWhiteSpace($SQLDepartment)) { $SQLDepartment = "Unknown" } if ([string]::IsNullOrWhiteSpace($SQLStandard)) { $SQLStandard = "Unknown" } if ($null -eq $SQLValidFrom) { $SQLValidFrom = Get-Date } if ($null -eq $SQLModified) { $SQLModified = Get-Date } if (-not [string]::IsNullOrWhiteSpace($SQLUniversalId)) { Write-Host "Calling MIME export for SQLUniversalId $SQLUniversalId" Write-Log "Calling MIME export for SQLUniversalId $SQLUniversalId" Export-MimeSqlDocument -SQLUniversalId $SQLUniversalId } else { Write-Host "Skipping MIME export because SQLUniversalId is empty" Write-Log "Skipping MIME export because SQLUniversalId is empty" } $MimeFolder = Join-Path $MimeOutputRoot $SQLUniversalId # **************************************** # Upload all files from MIME folder to Attachments Valid # except DOCX, because DOCX goes to Valid Documents # **************************************** $AttachmentFolderName = $SQLDocNumber $SPOAttachmentFolderUrl = "$SPOAttachmentLibRoot/$AttachmentFolderName" Write-Host "AttachmentFolderName = $AttachmentFolderName" Write-Log "AttachmentFolderName = $AttachmentFolderName" Write-Host "SPOAttachmentFolderUrl = $SPOAttachmentFolderUrl" Write-Log "SPOAttachmentFolderUrl = $SPOAttachmentFolderUrl" Connect-PnPOnline ` -Url $ShareflexWorkspaceSite ` -ClientId $clientId ` -CertificatePath $pfxpath ` -CertificatePassword (ConvertTo-SecureString -AsPlainText $certpassword -Force) ` -Tenant $tenantid ` -WarningAction Ignore Write-Host "Connected to Workspace for attachment upload" Write-Log "Connected to Workspace for attachment upload" Write-Host "Checking attachment folder $SPOAttachmentFolderUrl" Write-Log "Checking attachment folder $SPOAttachmentFolderUrl" try { $ExistingAttachmentFolder = Get-PnPFolder -Url $SPOAttachmentFolderUrl -ErrorAction Stop Write-Host "Attachment folder already exists: $AttachmentFolderName" Write-Log "Attachment folder already exists: $AttachmentFolderName" } catch { Write-Host "Creating attachment folder: $AttachmentFolderName" Write-Log "Creating attachment folder: $AttachmentFolderName" Add-PnPFolder -Name $AttachmentFolderName -Folder $SPOAttachmentLibRoot -ErrorAction Stop | Out-Null Write-Host "Attachment folder created OK: $AttachmentFolderName" Write-Log "Attachment folder created OK: $AttachmentFolderName" } $AttachmentFiles = Get-ChildItem -Path $MimeFolder -File | Where-Object { $_.Extension.ToLower() -ne ".docx" } if ($AttachmentFiles.Count -eq 0) { Write-Host "No attachment files found in $MimeFolder to upload to Attachments Valid" Write-Log "No attachment files found in $MimeFolder to upload to Attachments Valid" } else { Write-Host "Found $($AttachmentFiles.Count) attachment file(s) in $MimeFolder for Attachments Valid upload" Write-Log "Found $($AttachmentFiles.Count) attachment file(s) in $MimeFolder for Attachments Valid upload" $SPOAttachmentLibrary = Get-PnPList -Identity $ShareflexAttachmentLibraryName -ErrorAction Stop $SPOAttachmentContentTypes = Get-PnPProperty -ClientObject $SPOAttachmentLibrary -Property ContentTypes $SPOAttachmentContentType = $SPOAttachmentContentTypes | Where-Object { $_.Name -eq $SPOAttachmentContentTypeName } | Select-Object -First 1 if ($null -eq $SPOAttachmentContentType) { throw "Content type '$SPOAttachmentContentTypeName' not found on library '$ShareflexAttachmentLibraryName'." } $SPOAttachmentContentTypeId = $SPOAttachmentContentType.StringId foreach ($AttachmentFile in $AttachmentFiles) { $AttachmentFilePath = $AttachmentFile.FullName $AttachmentFileName = $AttachmentFile.Name Write-Host "Uploading attachment file $AttachmentFileName to $SPOAttachmentFolderUrl" Write-Log "Uploading attachment file $AttachmentFileName to $SPOAttachmentFolderUrl" $SPOAttachmentValues = @{ "ContentTypeId" = $SPOAttachmentContentTypeId "qmRecordNo" = $SQLDocNumber "qmRevisionNo" = $SQLRevisionNo "qmStatus" = "Valid" "qmStatusEn" = "Valid" } try { $UploadedAttachmentFile = Add-PnPFile ` -Path $AttachmentFilePath ` -Folder $SPOAttachmentFolderUrl ` -Values $SPOAttachmentValues ` -ErrorAction Stop Write-Host "Attachment uploaded OK: $AttachmentFileName" Write-Log "Attachment uploaded OK: $AttachmentFileName" $CreatedAttachmentItem = Get-PnPFile -Url $UploadedAttachmentFile.ServerRelativeUrl -AsListItem Get-PnPProperty -ClientObject $CreatedAttachmentItem -Property ContentType | Out-Null Write-Host "Attachment File: $($CreatedAttachmentItem['FileLeafRef'])" Write-Log "Attachment File: $($CreatedAttachmentItem['FileLeafRef'])" Write-Host "Attachment Content type: $($CreatedAttachmentItem.ContentType.Name)" Write-Log "Attachment Content type: $($CreatedAttachmentItem.ContentType.Name)" Write-Host "Attachment qmRecordNo: $($CreatedAttachmentItem['qmRecordNo'])" Write-Log "Attachment qmRecordNo: $($CreatedAttachmentItem['qmRecordNo'])" Write-Host "Attachment qmRevisionNo: $($CreatedAttachmentItem['qmRevisionNo'])" Write-Log "Attachment qmRevisionNo: $($CreatedAttachmentItem['qmRevisionNo'])" } catch { Write-Host "ERROR uploading attachment file $AttachmentFileName for row $RowCounter : $($_.Exception.Message)" Write-Log "ERROR uploading attachment file $AttachmentFileName for row $RowCounter : $($_.Exception.Message)" } } } # **************************************** # Upload docx file to valid documents library # **************************************** Write-Host "Looking for DOCX in $MimeFolder" Write-Log "Looking for DOCX in $MimeFolder" $DocxFile = Get-ChildItem -Path $MimeFolder -File -Filter "*.docx" | Select-Object -First 1 if ($null -eq $DocxFile) { Write-Host "No DOCX file found in $MimeFolder" Write-Log "No DOCX file found in $MimeFolder" continue } $LocalTestFilePath = $DocxFile.FullName Connect-PnPOnline ` -Url $ShareflexValidDocs ` -ClientId $clientId ` -CertificatePath $pfxpath ` -CertificatePassword (ConvertTo-SecureString -AsPlainText $certpassword -Force) ` -Tenant $tenantid ` -WarningAction Ignore Write-Host "Using DOCX file for SharePoint upload: $LocalTestFilePath" Write-Log "Using DOCX file for SharePoint upload: $LocalTestFilePath" $FolderName = $SQLDocNumber $SPOFolderUrl = "$SPODocLibRoot/$FolderName" Write-Host "Checking folder $SPOFolderUrl" Write-Log "Checking folder $SPOFolderUrl" try { $ExistingFolder = Get-PnPFolder -Url $SPOFolderUrl -ErrorAction Stop Write-Host "Folder already exists: $FolderName" Write-Log "Folder already exists: $FolderName" } catch { Write-Host "Creating folder: $FolderName" Write-Log "Creating folder: $FolderName" Add-PnPFolder -Name $FolderName -Folder $SPODocLibRoot -ErrorAction Stop | Out-Null Write-Host "Folder created OK: $FolderName" Write-Log "Folder created OK: $FolderName" } Write-Host "Preparing content type $SPOContentTypeName" Write-Log "Preparing content type $SPOContentTypeName" $SPOContentType = Get-PnPContentType -Identity $SPOContentTypeName $SPOContentType = Get-PnPProperty -ClientObject $SPOContentType -Property StringId $SPOContentTypeId = $SPOContentType.StringId $FileName = Split-Path $LocalTestFilePath -Leaf $ServerRelativeFileUrl = "$SPOFolderUrl/$FileName" $SPOValues = @{ "ContentTypeId" = $SPOContentTypeId #Document "Title" = $SQLDocTitle "qmDocumentTitle" = $SQLDocTitle "qmDocumentNo" = $SQLDocNumber "qmDocumentType" = $SQLDocType "qmTemplateNo" = $SQLTemplateNo "qmTemplateTitle" = $SQLTemplateTitle "qmEditor" = $SQLEditor "qmDocumentLanguage" = $SQLDocLanguage "qmNotificationList" = $SQLNotificationUsers #Revision "qmRevisionNo" = $SQLRevisionNo "qmRevisionReason" = $SQLRevisionReason "qmRevisionChange" = $SQLRevisionChange "qmValidFrom" = $SQLValidFrom "qmValidUntil" = $SQLValidUntil #Categories "qmClient" = $SQLClient "qmProcess1" = $SQLProcessGroup "qmDepartment" = $SQLDepartment "qmProcess2" = $SQLProcess2 "qmStandard" = $SQLStandard "qmProcess3" = $SQLSubProcess #Approval "qmReviewer" = $SQLReviewer "qmApprover" = $SQLApprover "qmConfirmer" = $SQLConfirmer "qmReviewTxt" = $SQLReviewResult "qmApprovalTxt" = $SQLApprovalResult "qmConfirmationTxt" = $SQLConfirmationResult #System / general "qmRecordId" = $SQLUniversalId "qmRecordNo" = $SQLDocNumber "qmContentType" = "QM Document" "qmStatus" = "Valid" "qmStatusEn" = "Valid" "qmDocumentUrl" = $ServerRelativeFileUrl "qmComment" = "Test item created from SQL row $RowCounter" "qmModified" = $SQLModified "qmCheckedOut" = $false "qmInTraining" = $false "qmTrainingMandatory" = $false "qmValidityDoNotUpdate" = $false } # remove null values from hashtable $NullKeys = @() foreach ($key in $SPOValues.Keys) { if ($null -eq $SPOValues[$key]) { $NullKeys += $key } } foreach ($key in $NullKeys) { $SPOValues.Remove($key) } Write-Host "Uploading $LocalTestFilePath to $SPOFolderUrl" Write-Log "Uploading $LocalTestFilePath to $SPOFolderUrl" try { $UploadedFile = Add-PnPFile ` -Path $LocalTestFilePath ` -Folder $SPOFolderUrl ` -Values $SPOValues ` -ErrorAction Stop Write-Host "Uploaded OK" Write-Log "Uploaded OK" $CreatedItem = Get-PnPFile -Url $UploadedFile.ServerRelativeUrl -AsListItem Get-PnPProperty -ClientObject $CreatedItem -Property ContentType | Out-Null Write-Host "--------------------------------------------------" Write-Log "--------------------------------------------------" Write-Host "Created Shareflex item from SQL row" Write-Log "Created Shareflex item from SQL row" Write-Host "File: $($CreatedItem['FileLeafRef'])" Write-Log "File: $($CreatedItem['FileLeafRef'])" Write-Host "Folder: $FolderName" Write-Log "Folder: $FolderName" Write-Host "Content type: $($CreatedItem.ContentType.Name)" Write-Log "Content type: $($CreatedItem.ContentType.Name)" Write-Host "Title: $($CreatedItem['Title'])" Write-Log "Title: $($CreatedItem['Title'])" Write-Host "qmDocumentTitle: $($CreatedItem['qmDocumentTitle'])" Write-Log "qmDocumentTitle: $($CreatedItem['qmDocumentTitle'])" Write-Host "qmDocumentNo: $($CreatedItem['qmDocumentNo'])" Write-Log "qmDocumentNo: $($CreatedItem['qmDocumentNo'])" Write-Host "qmDocumentType: $($CreatedItem['qmDocumentType'])" Write-Log "qmDocumentType: $($CreatedItem['qmDocumentType'])" Write-Host "qmClient: $($CreatedItem['qmClient'])" Write-Log "qmClient: $($CreatedItem['qmClient'])" Write-Host "qmDepartment: $($CreatedItem['qmDepartment'])" Write-Log "qmDepartment: $($CreatedItem['qmDepartment'])" Write-Host "qmStandard: $($CreatedItem['qmStandard'])" Write-Log "qmStandard: $($CreatedItem['qmStandard'])" Write-Host "qmRevisionNo: $($CreatedItem['qmRevisionNo'])" Write-Log "qmRevisionNo: $($CreatedItem['qmRevisionNo'])" Write-Host "qmDocumentUrl: $($CreatedItem['qmDocumentUrl'])" Write-Log "qmDocumentUrl: $($CreatedItem['qmDocumentUrl'])" } catch { Write-Host "ERROR creating Shareflex item for row $RowCounter : $($_.Exception.Message)" Write-Log "ERROR creating Shareflex item for row $RowCounter : $($_.Exception.Message)" } } } } catch { Write-Host "ERROR during SQL to Shareflex test: $($_.Exception.Message)" Write-Log "ERROR during SQL to Shareflex test: $($_.Exception.Message)" } finally { if ($SQLConnection.State -eq [System.Data.ConnectionState]::Open) { $SQLConnection.Close() } } } else { Write-Host "SQL to Shareflex test skipped" Write-Log "SQL to Shareflex test skipped" } |
Conclusion
Migrating from Lotus Notes to Shareflex QMS does not have to be overly complex. By first moving the Notes database to SQL with Lialis LNExtract, including daily delta updates, a stable foundation is created. From there, PnP PowerShell can be used to load the documents and attachments into Shareflex QMS with the right metadata and structure. This approach combines the safety of a lift-and-shift extraction with the flexibility to reshape the content for a modern SharePoint-based quality management solution.




