Public/FlyTeamsApi.ps1
|
<#
.SYNOPSIS Add mappings into the specified Teams project. .DESCRIPTION Add mappings into the specified Teams project. .PARAMETER Project Specify the name of the project to import mappings. .PARAMETER Path Specify the csv file path of the project mappings to import. .OUTPUTS None #> function Import-FlyTeamsMappings { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [String] ${Project}, [Parameter(Mandatory = $true)] [String] ${Path} ) Process { 'Calling method: Import-FlyTeamsMappings' | Write-Debug $PSBoundParameters | Out-DebugParameter | Write-Debug Try { $targetProject = Get-FlyProjectByName -ProjectName $Project $mappings = New-Object System.Collections.ArrayList; $importedMappings = Get-FlyMappingsFromCsv -Path $Path #Construct the project mapping list to import foreach ($mapping in $importedMappings) { $item = [PSCustomObject]@{ "enableChannelMapping" = $false "includeOtherChannels" = $false "sourceName" = $mapping.'Source Team name' "sourceIdentity" = $mapping."Source Team email address" "destinationName" = $mapping.'Destination Team name' "destinationIdentity" = $mapping."Destination Team email address" "channelMapping" = @() } if ($mapping.'Channel mappings' -eq 'Enabled') { $item.enableChannelMapping = $true $channelMapping = [PSCustomObject]@{ "sourceName" = $mapping.'Source channel name' "destinationType" = Get-FlyTeamsChannelType $mapping.'Destination channel type' "destinationName" = $mapping.'Destination channel name' } $item.channelMapping = @($channelMapping) } [void]$mappings.Add($item); } #Import project mapping list to the project [System.Net.HttpWebRequest]::DefaultMaximumErrorResponseLength = -1 $result = Add-FlyTeamsMappings -ProjectId $targetProject.Id -TeamsMappingCreationModel $mappings.ToArray() if ($result) { Write-Host 'Successfully added the mappings to the project.' -ForegroundColor Green } } Catch { Write-Host 'Failed to add the mappings to the project.' -ForegroundColor Red if ($_.ErrorDetails.Message) { $errorModel = ConvertFrom-Json $_.ErrorDetails.Message if ($errorModel.ErrorCode -eq 'ProjectMappingDuplicated') { Write-Host 'ErrorDetail : ProjectMappingDuplicated' -ForegroundColor Red $errorDetails = ConvertFrom-Json $errorModel.ErrorMessage $errorDetails | Select-Object SourceIdentity, DestinationIdentity, ProjectName | Format-Table } else { Write-Host $_.ErrorDetails.Message -ForegroundColor Red } } Write-Error $_.Exception throw } } } <# .SYNOPSIS Export the Teams migration mapping status to a csv file. .DESCRIPTION Export the Teams migration mapping status to a csv file. .PARAMETER Project Specify the name of the project to export mappings. .PARAMETER OutFile Specify the csv file path of the project mappings to export. .PARAMETER Mappings Specify the csv file to filter specific project mappings to export, export all mappings of the project if not specified. .OUTPUTS None #> function Export-FlyTeamsMappingStatus { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [String] ${Project}, [Parameter(Mandatory = $true)] [String] ${OutFile}, [Parameter(Mandatory = $false)] [String] ${Mappings} ) Process { 'Calling method: Export-FlyTeamsMappingStatus' | Write-Debug $PSBoundParameters | Out-DebugParameter | Write-Debug Try { $targetProject = Get-FlyProjectByName -ProjectName $Project -PlatformType 'Teams' $result = New-Object System.Collections.ArrayList; #Retrieve the project mappings from the specified project $allMappings = Get-FlyAllProjectMappings -ProjectId $targetProject.Id #Match the project mapping list between csv file and specified project if ($Mappings) { $targetMappings = Get-FlyMappingsFromCsv -Path $Mappings foreach ($target in $targetMappings) { foreach ($mapping in $allMappings) { $sourceIdentity = [System.Web.HttpUtility]::UrlDecode($target.'Source Team email address') $destinationIdentity = [System.Web.HttpUtility]::UrlDecode($target.'Destination Team email address') if ($mapping.SourceIdentity -eq $sourceIdentity -and $mapping.DestinationIdentity -eq $destinationIdentity) { [void]$result.Add($mapping); break; } } } } else { $result = @($allMappings) } if ($result.Count -gt 0) { $folderPath = [System.IO.Path]::GetDirectoryName($OutFile) If (-not (Test-Path $folderPath)) { # Folder does not exist, create it [void](New-Item -Path $folderPath -ItemType Directory) } #Output the matched project mappings to specified file path in csv format $result | ForEach-Object { Convert-FlyMappingStatus -Mapping $_ } | Export-Csv -Path $OutFile -NoTypeInformation Write-Host 'Successfully retrieved the migration mappings. File path:' $OutFile -ForegroundColor Green } else { throw 'No mapping in the CSV file matches the existing migration mappings in this project.' } } Catch { Write-Host 'Failed to retrieve the migration mappings.' -ForegroundColor Red ErrorDetail -Error $_ throw } } } <# .SYNOPSIS Generate migration report for the specified project mappings. .DESCRIPTION Generate migration report for the specified project mappings. .PARAMETER Project Specify the name of the project to generate their migration report. .PARAMETER OutFolder Specify the folder path of migration report file to download. .PARAMETER FileType Specify the format of the generated report file, CSV or Excel, optional for CSV type. .PARAMETER Mappings Specify the csv file to filter specific project mappings to generate report, for all mappings of the project if not specified. .PARAMETER TimeZoneOffset Specify the UTC time offset of current browser. This value will be used to adjust time values when generating the report file, optional for UTC timezone. .PARAMETER Include Specify a list of objects to be included in the migration report, use Tab for available values, optional if you do not export object details. .OUTPUTS None #> function Export-FlyTeamsMigrationReport { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [String] ${Project}, [Parameter(Mandatory = $true)] [String] ${OutFolder}, [Parameter(Mandatory = $false)] [String] ${Mappings}, [Parameter(Mandatory = $false)] [ValidateSet('CSV', 'Excel')] [String] ${FileType} = [ReportFileType]::CSV, [Parameter(Mandatory = $false)] [Int32] ${TimeZoneOffset}, [Parameter(Mandatory = $false)] [ValidateSet('ErrorObjects', 'WarningObjects', 'SuccessfulObjects', 'SkippedObjects', 'FilterOutObjects', 'NotFoundObjects', 'ErrorIgnoredObjects', 'UnsupportedObjects')] [String[]] ${Include} ) Process { 'Calling method: Export-FlyTeamsMigrationReport' | Write-Debug $PSBoundParameters | Out-DebugParameter | Write-Debug Try { $targetProject = Get-FlyProjectByName -ProjectName $Project -PlatformType 'Teams' $targetMappings = Get-FlyTeamsMappings -ProjectId $targetProject.Id -Mappings $Mappings #Construct the settings of report job $reportSetting = [PSCustomObject]@{ "includeMappingSummary" = $true "includeDetails" = $false "reportItemStatus" = @() "reportFileType" = $FileType "isSelectAll" = $true "mappingIds" = @() "timeZone" = $TimeZoneOffset } if ($Include -and $Include.Count -gt 0) { $reportSetting.includeDetails = $true $reportSetting.reportItemStatus = $Include -replace "ErrorObjects", "FailedObjects" } if ($targetMappings -and @($targetMappings).Count -gt 0) { $mappingIds = $targetMappings | Select-Object -Property Id | ForEach-Object { "$($_.Id)" } $reportSetting.mappingIds = @($mappingIds) $reportSetting.isSelectAll = $false } #Trigger the migration report job and get the job id $jobId = Start-FlyTeamsReportJob -ProjectId $targetProject.Id -GenerateReportSettingsModel $reportSetting #Monitor the job status and download the report file when job is finished while ($true) { Write-Host 'The report generation job is running.' -ForegroundColor Green Start-Sleep -Seconds 60 $job = Get-FlyReportJobs -RequestBody @($jobId) $jobStatus = $job.data[0].Status if ($jobStatus -eq [MappingJobStatus]::Finished -or $jobStatus -eq [MappingJobStatus]::FinishedWithException) { Write-Host 'The report generation job is finished.' -ForegroundColor Green $result = Get-FlyReportUrl -JobId $jobId if ($null -ne $result.ReportUrl) { $fileName = Split-Path $([uri]$result.ReportUrl).AbsolutePath -Leaf $filePath = Join-Path -Path $OutFolder -ChildPath $fileName If (-not (Test-Path $OutFolder)) { # Folder does not exist, create it [void](New-Item -Path $OutFolder -ItemType Directory) } Invoke-WebRequest -URI $result.ReportUrl -OutFile $filePath -UseBasicParsing Write-Host 'Successfully downloaded the job report. Report path:' $filePath -ForegroundColor Green } break; } elseif ($jobStatus -eq [MappingJobStatus]::Failed -or $jobStatus -eq [MappingJobStatus]::Stopped) { throw ('The report generation job is {0} with id {1}' -f [MappingJobStatus].GetEnumName($jobStatus), $job.data[0].JobName) } } } Catch { Write-Host 'Failed to generate the migration report.' -ForegroundColor Red ErrorDetail -Error $_ throw } } } <# .SYNOPSIS Start a pre-scan job against the selected project mappings. .DESCRIPTION Start a pre-scan job against the selected project mappings. .PARAMETER Project Specify the name of the project to run job. .PARAMETER Mappings Specify the csv file to filter specific project mappings to run job, for all mappings of the project if not specified. .OUTPUTS A Boolean value indicates whether the work has started successfully #> function Start-FlyTeamsPreScan { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [String] ${Project}, [Parameter(Mandatory = $false)] [String] ${Mappings} ) Process { 'Calling method: Start-FlyTeamsPreScan' | Write-Debug $PSBoundParameters | Out-DebugParameter | Write-Debug Try { $targetProject = Get-FlyProjectByName -ProjectName $Project $targetMappings = Get-FlyTeamsMappings -ProjectId $targetProject.Id -Mappings $Mappings #Construct the settings of the migration job $jobSettings = [PSCustomObject]@{ "type" = [MappingJobType]::Assessment "isSelectAll" = $true "mappingIds" = @() } if ($targetMappings -and @($targetMappings).Count -gt 0) { $mappingIds = $targetMappings | Select-Object -Property Id | ForEach-Object { "$($_.Id)" } $jobSettings.mappingIds = @($mappingIds) $jobSettings.isSelectAll = $false } $result = Start-FlyTeamsPreScanJob -ProjectId $targetProject.Id -ProjectMappingOperationModel $jobSettings if ($result) { Write-Host 'The job has started.' -ForegroundColor Green } } Catch { Write-Host 'Failed to start the job.' -ForegroundColor Red ErrorDetail -Error $_ throw } } } <# .SYNOPSIS Start a verify job against the selected project mappings. .DESCRIPTION Start a verify job against the selected project mappings. .PARAMETER Project Specify the name of the project to run job. .PARAMETER Mappings Specify the csv file to filter specific project mappings to run job, for all mappings of the project if not specified. .OUTPUTS A Boolean value indicates whether the job has started successfully #> function Start-FlyTeamsVerification { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [String] ${Project}, [Parameter(Mandatory = $false)] [String] ${Mappings} ) Process { 'Calling method: Start-FlyTeamsVerification' | Write-Debug $PSBoundParameters | Out-DebugParameter | Write-Debug Try { $targetProject = Get-FlyProjectByName -ProjectName $Project $targetMappings = Get-FlyTeamsMappings -ProjectId $targetProject.Id -Mappings $Mappings #Construct the settings of the migration job $jobSettings = [PSCustomObject]@{ "type" = [MappingJobType]::Validation "isSelectAll" = $true "mappingIds" = @() } if ($targetMappings -and @($targetMappings).Count -gt 0) { $mappingIds = $targetMappings | Select-Object -Property Id | ForEach-Object { "$($_.Id)" } $jobSettings.mappingIds = @($mappingIds) $jobSettings.isSelectAll = $false } $result = Start-FlyTeamsVerificationJob -ProjectId $targetProject.Id -ProjectMappingOperationModel $jobSettings if ($result) { Write-Host 'The job has started.' -ForegroundColor Green } } Catch { Write-Host 'Failed to start the job.' -ForegroundColor Red ErrorDetail -Error $_ throw } } } <# .SYNOPSIS Start a migration job against the selected project mappings. .DESCRIPTION Start a migration job against the selected project mappings. .PARAMETER Project Specify the name of the project to run job. .PARAMETER Mode Specify the mode of the migration job, use Tab for available values. .PARAMETER Mappings Specify the csv file to filter specific project mappings to run job, for all mappings of the project if not specified. .PARAMETER ScheduleTime Specify the time when you want the job to be scheduled. By default the job will be executed as soon as possible, optional for no schedule. .OUTPUTS A Boolean value indicates whether the job has started successfully #> function Start-FlyTeamsMigration { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [String] ${Project}, [Parameter(Mandatory = $true)] [ValidateSet('FullMigration', 'IncrementalMigration', 'ErrorOnly', 'MembershipOnly')] [String] ${Mode}, [Parameter(Mandatory = $false)] [String] ${Mappings}, [Parameter(Mandatory = $false)] [Datetime] ${ScheduleTime} ) Process { 'Calling method: Start-FlyTeamsMigration' | Write-Debug $PSBoundParameters | Out-DebugParameter | Write-Debug Try { $targetProject = Get-FlyProjectByName -ProjectName $Project $targetMappings = Get-FlyTeamsMappings -ProjectId $targetProject.Id -Mappings $Mappings #Construct the settings of the migration job $jobSettings = [PSCustomObject]@{ "type" = $Mode "scheduledTime" = 0 "isSelectAll" = $true "mappingIds" = @() } if ($targetMappings -and @($targetMappings).Count -gt 0) { $mappingIds = $targetMappings | Select-Object -Property Id | ForEach-Object { "$($_.Id)" } $jobSettings.mappingIds = @($mappingIds) $jobSettings.isSelectAll = $false } if ($ScheduleTime) { $jobSettings.scheduledTime = $ScheduleTime.Ticks } $result = Start-FlyTeamsMigrationJob -ProjectId $targetProject.Id -MigrationJobSettingsModel $jobSettings if ($result) { Write-Host 'The job has started.' -ForegroundColor Green } } Catch { Write-Host 'Failed to start the job.' -ForegroundColor Red ErrorDetail -Error $_ throw } } } <# .SYNOPSIS Export the Teams migration policy to a JSON file. .DESCRIPTION Export the Teams migration policy to a JSON file. .PARAMETER PolicyName Specify the name of the migration policy to export. .PARAMETER OutFile Specify the JSON file path to export the migration policy. .OUTPUTS None #> function Export-FlyTeamsPolicy { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [String] ${PolicyName}, [Parameter(Mandatory = $true)] [String] ${OutFile} ) Process { 'Calling method: Export-FlyTeamsPolicy' | Write-Debug $PSBoundParameters | Out-DebugParameter | Write-Debug Try { $targetPolicy = Get-FlyPolicyByName -PolicyName $PolicyName -PlatformType 'Teams' $policyModel = Get-FlyTeamsPolicy -Id $targetPolicy.Id if ($null -ne $policyModel) { $policyModel.UserMappingProfileId = Get-FlyMappingSettingById -MappingId $policyModel.UserMappingProfileId -Type 'User' $policyModel.EmailLabelMappingProfileId = Get-FlyMappingSettingById -MappingId $policyModel.EmailLabelMappingProfileId -Type 'Label' $policyModel.TeamsLabelMappingProfileId = Get-FlyMappingSettingById -MappingId $policyModel.TeamsLabelMappingProfileId -Type 'Label' $policyModel.URLMappingProfileId = Get-FlyMappingSettingById -MappingId $policyModel.URLMappingProfileId -Type 'URL' $policyModel.ConversationTimeLaterThan = Convert-TicksToDateTime -Ticks $policyModel.ConversationTimeLaterThan -ShowHourFormat $false $policyModel.Notification.EmailTemplateId = Get-FlyEmailTemplateById -TemplateId $policyModel.Notification.EmailTemplateId $policyModel.Notification.ProjectMigrationEmailTemplateId = Get-FlyEmailTemplateById -TemplateId $policyModel.Notification.ProjectMigrationEmailTemplateId $policyModel.Notification.StartTime = Convert-TicksToDateTime -Ticks $policyModel.Notification.StartTime -ShowHourFormat $true $policyModel.Notification.EndTime = Convert-TicksToDateTime -Ticks $policyModel.Notification.EndTime -ShowHourFormat $true $policyModel.AdvancedExchangePolicyId = if ($null -eq $policyModel.AdvancedExchangePolicyId -or $policyModel.AdvancedExchangePolicyId -eq [Guid]::Empty) { '' } else { (Get-FlyExchangePolicy -Id $policyModel.AdvancedExchangePolicyId).Name } $policyModel.AdvancedSharePointPolicyId = if ($null -eq $policyModel.AdvancedSharePointPolicyId -or $policyModel.AdvancedSharePointPolicyId -eq [Guid]::Empty) { '' } else { (Get-FlySharePointPolicy -Id $policyModel.AdvancedSharePointPolicyId).Name } $folderPath = [System.IO.Path]::GetDirectoryName($OutFile) If (-not (Test-Path $folderPath)) { # Folder does not exist, create it [void](New-Item -Path $folderPath -ItemType Directory) } #Output the matched policy to specified file path in JSON format $policyModel.Notification = $policyModel.Notification | Select-Object * -ExcludeProperty SendToSourceEmail, SendToDestinationEmail $result = ($policyModel | Select-Object * -ExcludeProperty IsDefault, CreateTime, CreateBy, LastModifyTime, LastModifyBy , Id, IsBackupFilePermissions, IsBackupDirectSitePermissions, IsBackupWholeStructureAndData, IsDisableAutoComplete, conversationTimeEarlierThan) | ConvertTo-Json -Depth 10 Set-Content -Path $OutFile -Value $result -Encoding UTF8 Write-Host 'Successfully exported the migration policy as JSON. File path:' $OutFile -ForegroundColor Green } else { throw 'No migration policy name matches the existing migration polices.' } } Catch { Write-Host 'Failed to retrieve the migration policy.' -ForegroundColor Red ErrorDetail -Error $_ throw } } } <# .SYNOPSIS Import the Teams migration policy from a JSON file. .DESCRIPTION Import the Teams migration policy from a JSON file. .PARAMETER Path Specify the JSON file path to import the migration policy. .OUTPUTS The name of the created migration policy. #> function Import-FlyTeamsPolicy { [CmdletBinding()] Param( [Parameter(Mandatory = $true)] [String] ${Path} ) Process { 'Calling method: Import-FlyTeamsPolicy' | Write-Debug $PSBoundParameters | Out-DebugParameter | Write-Debug try { $policyModel = Get-FlyPolicyFromJson -Path $Path $validateProperties = ("backupObjects", "enableMigrateGuestUsers", "enableMigrateExternalUsers", "isPostMessage", "isCovertToHtml", "conversationTimeLaterThan", "messageTimeZoneId", "isBackupMeetingRecords", "isBackupOnlyTeamsAssociatedContent", "isBackupMailbox", "advancedExchangePolicyId", "advancedSharePointPolicyId", "folderConflictResolution", "fileConflictResolution", "itemConflictResolution", "isReplaceEmailAddress", "isReplaceMeetingLink", "isSyncTeamGroupPrivacyChanges", "isRemoveSourceFromFiles", "emailSensitivityLabel", "teamsSensitivityLabel", "userMappingProfileId", "emailLabelMappingProfileId", "teamsLabelMappingProfileId", "userMappingRules", "urlMappingProfileId", "name", "description", "migrationModuleType", "notification", "customizeFeatures") Confirm-FlyObjectPropertyExistence -Object $policyModel -Properties $validateProperties if ([String]::IsNullOrWhiteSpace($policyModel.MessageTimeZoneId)) { throw "MessageTimeZoneId is required." } if ([int]$policyModel.TeamsSensitivityLabel -eq 0) { throw "TeamsSensitivityLabel can't be KeepExisting." } if ($null -eq $policyModel.BackupObjects -or -not (@($policyModel.BackupObjects) -contains 1)) { if ($policyModel.IsPostMessage -or $policyModel.IsCovertToHtml) { throw "IsPostMessage and IsCovertToHtml must be false when Channel Conversations is not selected." } } if (-not $policyModel.IsPostMessage) { if ($null -ne $policyModel.ConversationTimeLaterThan -and $policyModel.ConversationTimeLaterThan -ne '') { throw "ConversationTimeLaterThan must be null or empty when IsPostMessage is false." } } #mapping settings $policyModel.UserMappingProfileId = Get-FlyMappingSettingByName -MappingName $policyModel.UserMappingProfileId -Type 'User' $policyModel.EmailLabelMappingProfileId = Get-FlyMappingSettingByName -MappingName $policyModel.EmailLabelMappingProfileId -Type 'Label' -NeedValidation ([int]$policyModel.EmailSensitivityLabel -eq 3) $policyModel.TeamsLabelMappingProfileId = Get-FlyMappingSettingByName -MappingName $policyModel.TeamsLabelMappingProfileId -Type 'Label' -NeedValidation ([int]$policyModel.TeamsSensitivityLabel -eq 3) $policyModel.URLMappingProfileId = Get-FlyMappingSettingByName -MappingName $policyModel.URLMappingProfileId -Type 'URL' #advanced policies $policyModel.AdvancedExchangePolicyId = if ($null -ne $policyModel.AdvancedExchangePolicyId -and $policyModel.AdvancedExchangePolicyId -ne '') { (Get-FlyPolicyByName -PolicyName $policyModel.AdvancedExchangePolicyId -PlatformType 'Exchange').Id } else { $null } $policyModel.AdvancedSharePointPolicyId = if ($null -ne $policyModel.AdvancedSharePointPolicyId -and $policyModel.AdvancedSharePointPolicyId -ne '') { (Get-FlyPolicyByName -PolicyName $policyModel.AdvancedSharePointPolicyId -PlatformType 'SharePoint').Id } else { $null } #notification settings $policyModel.Notification = Resolve-FlyNotificationCreationModel -NotificationSettings $policyModel.Notification #Date time properties $policyModel.ConversationTimeLaterThan = if (Confirm-FlyDateTimeProperty -DateTimeValue $policyModel.ConversationTimeLaterThan -PropertyName 'ConversationTimeLaterThan') { Convert-DateTimeToTicks -DateTime $policyModel.ConversationTimeLaterThan } else { 0 } $policyModel.UserMappingRules = Resolve-FlyUserMappingRules -UserMappingRuleSettings $policyModel.UserMappingRules $result = Add-FlyTeamsPolicy -TeamsPolicyCreationModel $policyModel if ($result) { Write-Host 'Successfully created the migration policy.' -ForegroundColor Green } return $result.Name } catch { Write-Host 'Failed to create the migration policy.' -ForegroundColor Red ErrorDetail -Error $_ throw } } } <# .SYNOPSIS Create a new Teams migration policy. .DESCRIPTION Create a new Teams migration policy. .PARAMETER Policy Specify the Teams migration policy creation model. .OUTPUTS The created Teams migration policy. #> function New-FlyTeamsPolicy { [CmdletBinding()] Param( [Parameter(Mandatory = $true)] [TeamsPolicy] $Policy ) Process { 'Calling method: New-FlyTeamsPolicy' | Write-Debug $PSBoundParameters | Out-DebugParameter | Write-Debug try { if (-not ($Policy -is [TeamsPolicy])) { throw "Input is not TeamsPolicy." } if ([int]$Policy.TeamsSensitivityLabels -eq 0) { throw "TeamsSensitivityLabels can't be KeepExisting." } if (-not $Policy.EnableChannelConversations) { if ($Policy.EnableRecreateMessageAndHierarchy -or $Policy.EnableArchiveMessageToAnHTMLFile) { throw "EnableRecreateMessageAndHierarchy and EnableArchiveMessageToAnHTMLFile must be false when EnableChannelConversations is false." } } if (-not $Policy.EnableRecreateMessageAndHierarchy) { if ($null -ne $Policy.RecreateOnOrAfter -and $Policy.RecreateOnOrAfter -ne '') { throw "RecreateOnOrAfter must be null or empty when EnableRecreateMessageAndHierarchy is false." } } $backupObjects = New-Object System.Collections.ArrayList if ($Policy.EnableApps) { [void]$backupObjects.Add([TeamsObjectType]::TeamsApp) } if ($Policy.EnableChannelConversations) { [void]$backupObjects.Add([TeamsObjectType]::Conversation) } if ($Policy.EnableTabs) { [void]$backupObjects.Add([TeamsObjectType]::Tab) } if ($Policy.EnableTags) { [void]$backupObjects.Add([TeamsObjectType]::TeamTags) } if ($Policy.EnablePlanner) { [void]$backupObjects.Add([TeamsObjectType]::Planner) } if ($Policy.EnableShifts) { [void]$backupObjects.Add(7) } if ($Policy.EnableMembership) { [void]$backupObjects.Add([TeamsObjectType]::Membership) } if ($Policy.EnableMigrateAllDataInSPTeamSite -eq $Policy.EnableMigrateDefaultDocumentLibraryOnly) { throw "EnableMigrateAllDataInSPTeamSite and EnableMigrateDefaultDocumentLibraryOnly cannot be both true or both false." } $advancedExchangePolicyId = $null if (-not $Policy.EnableSimplePolicy -and $Policy.EnableMigrateGroupMailbox -and $null -ne $Policy.ExchangePolicyName -and $Policy.ExchangePolicyName -ne '') { $advancedExchangePolicyId = (Get-FlyPolicyByName -PolicyName $Policy.ExchangePolicyName -PlatformType 'Exchange').Id } elseif (-not $Policy.EnableSimplePolicy -and $Policy.EnableMigrateGroupMailbox) { throw "ExchangePolicyName is required when EnableSimplePolicy is false and EnableMigrateGroupMailbox is true." } elseif ($null -ne $Policy.ExchangePolicyName -and $Policy.ExchangePolicyName -ne '') { Write-Host ('Skip verify ExchangePolicyName: {0}, it will not be saved since EnableSimplePolicy is true or EnableMigrateGroupMailbox is false.' -f $Policy.ExchangePolicyName) -ForegroundColor Green } $advancedSharePointPolicyId = $null if (-not $Policy.EnableSimplePolicy -and $null -ne $Policy.SharePointPolicyName -and $Policy.SharePointPolicyName -ne '') { $advancedSharePointPolicyId = (Get-FlyPolicyByName -PolicyName $Policy.SharePointPolicyName -PlatformType 'SharePoint').Id } elseif (-not $Policy.EnableSimplePolicy) { throw "SharePointPolicyName is required when EnableSimplePolicy is false." } elseif ($null -ne $Policy.SharePointPolicyName -and $Policy.SharePointPolicyName -ne '') { Write-Host ('Skip verify SharePointPolicyName: {0}, it will not be saved since EnableSimplePolicy is true.' -f $Policy.SharePointPolicyName) -ForegroundColor Green } $policyModel = [PSCustomObject]@{ "backupObjects" = $backupObjects "enableMigrateGuestUsers" = $Policy.EnableMembersGuestUser "enableMigrateExternalUsers" = $Policy.EnableMembersExternalUser "isBackupMeetingRecords" = $Policy.EnableMeetingRecordings "isPostMessage" = $Policy.EnableRecreateMessageAndHierarchy "conversationTimeLaterThan" = if ($null -ne $Policy.RecreateOnOrAfter -and $Policy.RecreateOnOrAfter -ne '') { Convert-DateTimeToTicks -DateTime $Policy.RecreateOnOrAfter }else { 0 } "isCovertToHtml" = $Policy.EnableArchiveMessageToAnHTMLFile "messageTimeZoneId" = $Policy.TimeZoneForMessages "isBackupOnlyTeamsAssociatedContent" = $Policy.EnableMigrateDefaultDocumentLibraryOnly "isBackupMailbox" = $Policy.EnableMigrateGroupMailbox "advancedExchangePolicyId" = $advancedExchangePolicyId "advancedSharePointPolicyId" = $advancedSharePointPolicyId "folderConflictResolution" = $Policy.SPTeamSiteConflictResolution "fileConflictResolution" = $Policy.SPTeamSiteFilesConflictResolution "itemConflictResolution" = $Policy.ItemConflictResolution "isReplaceEmailAddress" = $Policy.EnableReplaceEmailAddresses "isReplaceMeetingLink" = $Policy.EnableReplaceMeetingLink "isSyncTeamGroupPrivacyChanges" = $Policy.EnableSyncPrivacySettings "emailSensitivityLabel" = $Policy.FilesSensitivityLabels "emailLabelMappingProfileId" = Get-FlyMappingSettingByName -MappingName $Policy.FilesLabelMappingName -Type 'Label' -NeedValidation ([int]$Policy.FilesSensitivityLabels -eq 3) "teamsSensitivityLabel" = $Policy.TeamsSensitivityLabels "teamsLabelMappingProfileId" = Get-FlyMappingSettingByName -MappingName $Policy.TeamsLabelMappingName -Type 'Label' -NeedValidation ([int]$Policy.TeamsSensitivityLabels -eq 3) "isRemoveSourceFromFiles" = $Policy.RemoveSourceIRMFromFiles "userMappingRules" = Initialize-FlyUserMappingRules -UserMappingRuleSettings $Policy.UserMappingRules "userMappingProfileId" = Get-FlyMappingSettingByName -MappingName $Policy.UserMappingName -Type 'User' "urlMappingProfileId" = Get-FlyMappingSettingByName -MappingName $Policy.URLMappingName -Type 'URL' "name" = $Policy.Name "description" = if ([String]::IsNullOrWhiteSpace($Policy.Description)) { '' } else { $Policy.Description } "migrationModuleType" = [MigrationModuleType]::Teams "notification" = Initialize-FlyNotificationCreationModel -NotificationSettings $Policy.Notification "customizeFeatures" = $Policy.CustomizeFeatures } $result = Add-FlyTeamsPolicy -TeamsPolicyCreationModel $policyModel if ($result) { Write-Host 'Successfully created the migration policy.' -ForegroundColor Green } return $result.Name } catch { Write-Host 'Failed to create the migration policy.' -ForegroundColor Red ErrorDetail -Error $_ throw } } } |