Add UserProfileTransfer so UserProfileBackup will work
This commit is contained in:
parent
157cc390f0
commit
115cf5dc06
89
Private/UserProfileTransfer.ps1
Normal file
89
Private/UserProfileTransfer.ps1
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
function Invoke-UserProfileTransfer {
|
||||
param($srcPath, $dstPath)
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Backs up a user profile to a specified filepath.
|
||||
.DESCRIPTION
|
||||
Takes a input of hostname and user and will make a copy of the user profile
|
||||
and the Microsoft Roaming Folder and back it up to a specified filepath.
|
||||
#>
|
||||
|
||||
#The folders that this back up file grabs
|
||||
$FoldersToCopy = @(
|
||||
'Desktop'
|
||||
'Downloads'
|
||||
'Favorites'
|
||||
'Documents'
|
||||
'Pictures'
|
||||
'Videos'
|
||||
'AppData\Local\Google\Chrome\User Data\Default\Bookmarks'
|
||||
'AppData\Roaming\Microsoft'
|
||||
'Sticky Notes'
|
||||
)
|
||||
|
||||
#Creates a log file
|
||||
New-Item -Path $dstPath\backuplog.txt -Force | Write-Verbose
|
||||
$log = Join-Path -Path $dstPath -ChildPath backuplog.txt
|
||||
|
||||
Write-Host "Copying profile to $dstPath"
|
||||
|
||||
for ($i = 0; $i -lt $FoldersToCopy.Length; $i++) {
|
||||
$Folder = $FoldersToCopy[$i]
|
||||
|
||||
Write-Progress -Activity "User Profile Transfer from $srcPath to $dstPath" -Status $Folder -PercentComplete ($i / $FoldersToCopy.Length)*100
|
||||
|
||||
$Source = Join-Path -Path $srcPath -ChildPath $Folder
|
||||
$Destination = $dstPath
|
||||
Write-Host "Copying $Folder"
|
||||
|
||||
if( $Folder -eq 'Sticky Notes'){
|
||||
$Source = Join-Path -Path $srcPath -ChildPath 'AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState'
|
||||
$Destination = Join-Path -Path "$dstPath" -ChildPath 'AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState'
|
||||
New-Item -Path $Destination -ItemType Directory | Write-Verbose
|
||||
}
|
||||
|
||||
if($Folder -eq 'AppData\Local\Google\Chrome\User Data\Default\Bookmarks'){
|
||||
if( -not ( Test-Path -Path $Source )){
|
||||
Write-Host "No Chrome Bookmarks present"
|
||||
continue
|
||||
}
|
||||
if( -not ( Test-Path -Path "$Destination")){
|
||||
Write-Warning "Restoring Chrome bookmarks but Chrome is not installed on this machine"
|
||||
|
||||
}
|
||||
if( -not ( Test-Path -Path "$Destination")){
|
||||
New-Item "$Destination" -ItemType Container | Write-Verbose
|
||||
}
|
||||
|
||||
Copy-Item $Source -Destination "$Destination" -Force | Out-File $log -Append
|
||||
Write-Host "complete"
|
||||
continue
|
||||
}
|
||||
|
||||
#Checks if folder paths are available
|
||||
if( -not ( Test-Path -Path $Source ) ){
|
||||
Write-Warning "Could not find path`t$Source"
|
||||
continue
|
||||
}
|
||||
|
||||
if( -not ( Test-Path -Path $Destination -PathType Container ) ){
|
||||
Write-Warning "Could not find path`t$Destination"
|
||||
continue
|
||||
}
|
||||
|
||||
if($Folder -eq 'AppData\Roaming\Microsoft'){
|
||||
#If it's time to copy AppData folder it changes the copy destination to build the proper directory tree
|
||||
|
||||
$Destination = Join-Path -Path $Destination -ChildPath 'AppData\Roaming\Microsoft'
|
||||
|
||||
Copy-Item -Path (Get-Item -Path "$Source\*" -Exclude ('Teams')).FullName -Destination $Destination -Recurse -Force -PassThru | Out-File $log -Append
|
||||
|
||||
Write-Host 'complete'
|
||||
continue
|
||||
}
|
||||
Copy-Item $Source -Destination $Destination -Recurse -PassThru | Out-File $log -Append
|
||||
Write-Host "complete"
|
||||
}
|
||||
Write-Progress -Activity "User Profile Transfer from $srcPath to $dstPath" -Completed
|
||||
#endregion
|
||||
}#End Function
|
||||
Loading…
Reference in a new issue