Add column mapping defaults functionality and example JSON file
This commit is contained in:
@@ -32,6 +32,8 @@ param(
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = "Stop"
|
||||
$script:SkippedImportFieldWarnings = @{}
|
||||
$script:ListImportTrackingFieldInternalName = "StartSPMigrationSourceUniqueId"
|
||||
$script:ListImportTrackingFieldDisplayName = "Start-SPMigration Source UniqueId"
|
||||
|
||||
function Initialize-SharePointPowerShell {
|
||||
if($null -eq $(Get-Module SharePointServer)) {
|
||||
@@ -2704,6 +2706,68 @@ function Import-SPDocumentLibraries {
|
||||
}
|
||||
}
|
||||
|
||||
function Ensure-SPMigrationListTrackingField {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[Microsoft.SharePoint.SPList]$List
|
||||
)
|
||||
|
||||
$field = Resolve-SPField -Fields $List.Fields -InternalName $script:ListImportTrackingFieldInternalName
|
||||
if ($null -ne $field) {
|
||||
return $field
|
||||
}
|
||||
|
||||
[void]$List.Fields.Add($script:ListImportTrackingFieldInternalName, [Microsoft.SharePoint.SPFieldType]::Text, $false)
|
||||
$List.Update()
|
||||
|
||||
$field = Resolve-SPField -Fields $List.Fields -InternalName $script:ListImportTrackingFieldInternalName
|
||||
if ($null -eq $field) {
|
||||
throw ("Konnte Tracking-Feld fuer idempotenten Listenimport nicht anlegen: {0}" -f $List.Title)
|
||||
}
|
||||
|
||||
$field.Title = $script:ListImportTrackingFieldDisplayName
|
||||
$field.Hidden = $true
|
||||
|
||||
try {
|
||||
$field.Indexed = $true
|
||||
}
|
||||
catch {
|
||||
Write-Warning ("Tracking-Feld konnte nicht indiziert werden: {0}. {1}" -f $List.Title, $_.Exception.Message)
|
||||
}
|
||||
|
||||
$field.Update()
|
||||
$List.Update()
|
||||
|
||||
return $field
|
||||
}
|
||||
|
||||
function Get-SPListItemByMigrationSourceUniqueId {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[Microsoft.SharePoint.SPList]$List,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$FieldInternalName,
|
||||
|
||||
[string]$SourceUniqueId
|
||||
)
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($SourceUniqueId)) {
|
||||
return $null
|
||||
}
|
||||
|
||||
$escapedValue = [System.Security.SecurityElement]::Escape($SourceUniqueId)
|
||||
$query = New-Object Microsoft.SharePoint.SPQuery
|
||||
$query.RowLimit = 1
|
||||
$query.Query = "<Where><Eq><FieldRef Name='$FieldInternalName' /><Value Type='Text'>$escapedValue</Value></Eq></Where>"
|
||||
|
||||
$matchingItems = $List.GetItems($query)
|
||||
if ($matchingItems.Count -eq 0) {
|
||||
return $null
|
||||
}
|
||||
|
||||
return $matchingItems[0]
|
||||
}
|
||||
function Import-SPLists {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
@@ -2755,10 +2819,12 @@ function Import-SPLists {
|
||||
|
||||
Write-Host ("Importiere Liste: {0}" -f $targetListTitle)
|
||||
$fieldMapping = Get-FieldMappingForContainer -MigrationMappingTable $MigrationMappingTable -ObjectType "List" -SourceTitle $sourceListTitle
|
||||
$trackingField = Ensure-SPMigrationListTrackingField -List $targetList
|
||||
|
||||
foreach ($sourceItem in $items) {
|
||||
$sourceItemId = [string](Get-ObjectPropertyValue -Object $sourceItem -PropertyName "Id")
|
||||
$sourceItemTitle = [string](Get-ObjectPropertyValue -Object $sourceItem -PropertyName "Title")
|
||||
$sourceItemUniqueId = [string](Get-ObjectPropertyValue -Object $sourceItem -PropertyName "UniqueId")
|
||||
$fileSystemObjectType = [string](Get-ObjectPropertyValue -Object $sourceItem -PropertyName "FileSystemObjectType")
|
||||
if ($fileSystemObjectType -eq "Folder") {
|
||||
Write-Warning ("Ordner in normalen Listen werden in dieser Version uebersprungen: {0}" -f $targetListTitle)
|
||||
@@ -2770,8 +2836,22 @@ function Import-SPLists {
|
||||
}
|
||||
|
||||
try {
|
||||
$targetItem = $targetList.Items.Add()
|
||||
$targetItem = Get-SPListItemByMigrationSourceUniqueId -List $targetList -FieldInternalName $trackingField.InternalName -SourceUniqueId $sourceItemUniqueId
|
||||
$isExistingItem = $null -ne $targetItem
|
||||
|
||||
if ($isExistingItem) {
|
||||
Write-Host ("Aktualisiere vorhandenes Listenelement: Liste '{0}', Quell-ItemId '{1}'" -f $targetListTitle, $sourceItemId)
|
||||
}
|
||||
else {
|
||||
$targetItem = $targetList.Items.Add()
|
||||
}
|
||||
|
||||
Apply-FieldMappingToItem -Item $targetItem -FieldMapping $fieldMapping -SourceFieldValues (Get-ObjectPropertyValue -Object $sourceItem -PropertyName "FieldValues") -SourceFieldTextValues (Get-ObjectPropertyValue -Object $sourceItem -PropertyName "FieldTextValues")
|
||||
|
||||
if (-not [string]::IsNullOrWhiteSpace($sourceItemUniqueId)) {
|
||||
$targetItem[$trackingField.InternalName] = $sourceItemUniqueId
|
||||
}
|
||||
|
||||
Save-SPListItem -Item $targetItem -Context ("Liste '{0}', Quell-ItemId '{1}', Titel '{2}'" -f $targetListTitle, $sourceItemId, $sourceItemTitle)
|
||||
}
|
||||
catch {
|
||||
|
||||
Reference in New Issue
Block a user