I made a simple dialog box to copy profile folders from one local user to another, using robocopy:
Code: Select all
$formProfileMigration_Load= {
# Get Local Profile List and Enumerate Source Profile
$ProfileList = Get-WmiObject -ComputerName $env:COMPUTERNAME Win32_UserProfile -filter "LocalPath Like 'C:\\Users\\%' AND special=False AND loaded=False" -ea stop | Select LocalPath
foreach ($User in $ProfileList)
{
Update-ComboBox $SourceBox ($User).LocalPath -Append
Update-ComboBox $DestinationBox ($User).LocalPath -Append
}
}
$DestinationBox_SelectedIndexChanged = {
if ($SourceBox.SelectedItem -eq $DestinationBox.SelectedItem)
{
Add-Type -AssemblyName PresentationCore, PresentationFramework
$ButtonType = [System.Windows.MessageBoxButton]::OK
$MessageboxTitle = "Warning"
$Messageboxbody = "Cannot copy into the same profile"
$MessageIcon = [System.Windows.MessageBoxImage]::Warning
[System.Windows.MessageBox]::Show($Messageboxbody, $MessageboxTitle, $ButtonType, $messageicon)
}
}
$buttonStart.add_Click({
# Error message in case there's no selected profile
if ($SourceBox.SelectedItem -eq $null -or $DestinationBox.SelectedItem -eq $null)
{
Add-Type -AssemblyName PresentationCore, PresentationFramework
$ButtonType = [System.Windows.MessageBoxButton]::OK
$MessageboxTitle = "Warning"
$MessageboxBody = "Please select a Profile"
$MessageIcon = [System.Windows.MessageBoxImage]::Warning
[System.Windows.MessageBox]::Show($Messageboxbody, $MessageboxTitle, $ButtonType, $messageicon)
}
# Set profile folders to copy
$FoldersToCopy = @(
"AppData\Local\Google"
"Desktop"
"Documents"
"Downloads"
"Favorites"
"Pictures"
"Videos"
)
# Setup progress bar
$progressbaroverlay1.Maximum = $FoldersToCopy.Count
# Set source and destination folders
$SourceRoot = "$($SourceBox.SelectedItem)"
$DestinationRoot = "$($DestinationBox.SelectedItem)"
# Copy folders and update the progress bar
foreach ($Folder in $FoldersToCopy)
{
$Source = Join-Path -Path $SourceRoot -ChildPath $Folder
$Destination = Join-Path -Path $DestinationRoot -ChildPath $Folder
robocopy.exe $Source $Destination /E /IS /NP /NFL
$progressbaroverlay1.PerformStep()
}
})
And I only have 3 folders copied:
I have to terminate the process manually in Task Manager.
When I press terminate in Task Manager, the progress bar gets filled and the window closes.
I have no errors/messages in the Output window.
How can I find out what's causing the freeze?
Thank you