Public/Start-Migration.ps1
<#
.SYNOPSIS Starts the migration process for user data. .DESCRIPTION Constructs the source and destination paths and initiates the migration process. Supports migrating a specific folder if specified. .PARAMETER SourceUsername The source username (e.g., "testu"). .PARAMETER DestinationUsername The destination username (e.g., "test.user"). .PARAMETER SharePath The shared path containing the user data (e.g., "\\testing\w10-home"). .PARAMETER LogFilePath The full path to the log file. .PARAMETER Folder The specific folder to migrate (e.g., "Desktop"). Optional. If not provided, the entire source directory is migrated. .PARAMETER DryRun Optional switch to test the migration process without copying files. .EXAMPLE Start-Migration -SourceUsername "testu" -DestinationUsername "test.user" -SharePath "\\testing\w10-home" -LogFilePath "C:\Logs\MigrationLog.log" .EXAMPLE Start-Migration -SourceUsername "testu" -DestinationUsername "test.user" -SharePath "\\testing\w10-home" -LogFilePath "C:\Logs\MigrationLog.log" -Folder "Desktop" #> function Start-Migration { param ( [Parameter(Mandatory = $True)] [string]$SourceUsername, [Parameter(Mandatory = $True)] [string]$DestinationUsername, [Parameter(Mandatory = $True)] [string]$SharePath, [Parameter(Mandatory = $True)] [string]$LogFilePath, [Parameter(Mandatory = $False)] [string]$Folder, [switch]$DryRun ) $sourcePath = Join-Path -Path $SharePath -ChildPath $SourceUsername $Config = Read-Config $fslogixPath = $Config["FileShares"]["FSLogixPath"] if ($fslogixPath) { $destinationPath = Join-Path -Path $fslogixPath -ChildPath $DestinationUsername } else { $destinationPath = Join-Path -Path $SharePath -ChildPath $DestinationUsername } $profilePath = $sourcePath -replace 'w10-home', 'w10-profile' $ExcludeFolders = @() $BookmarkPaths = @() $rawExclude = $Config["Settings"]["ExcludeFolder"] $rawBookmarks = $Config["Settings"]["BookmarkPaths"] if ($rawExclude) { $ExcludeFolders = $rawExclude -split ',\s*' } if ($rawBookmarks) { foreach ($bookmark in ($rawBookmarks -split ',\s*')) { $bookmarkFullPath = Join-Path -Path $profilePath -ChildPath $bookmark if (Test-Path $bookmarkFullPath) { $BookmarkPaths += $bookmarkFullPath } else { Write-Log -Message "WARNING: Bookmark path not found - $bookmarkFullPath" -LogFilePath $LogFilePath $BookmarkPaths += $bookmark # Still use the ini path if actual not found } } } $params = @{ SourcePath = $sourcePath DestinationPath = $destinationPath LogFilePath = $LogFilePath } if ($PSBoundParameters.ContainsKey('Folder')) { $params.Folder = $Folder } if ($ExcludeFolders.Count -gt 0) { $params.ExcludeFolders = $rawExclude } if ($BookmarkPaths.Count -gt 0) { $params.BookmarkPaths = $BookmarkPaths $params.IncludeBookmarks = $true } Write-Log -Message "INFO: Starting migration with parameters: $($params | Out-String)" -LogFilePath $LogFilePath Migrate-UserData @params } |