I’m actually not using Enter-PSSession, as I run the script from the source computer. Let me post my code just in case you have a different idea. This is not my script; I just modified it to remove things I don’t need to backup/restore.
##region Switch to Backup
Start-Sleep -Seconds 5
Write-Host “”
Write-Host “”
Write-Host “”
Write-Host -ForegroundColor Yellow “Standby Loading Backup Script…”
Start-Sleep -Seconds 5
Clear-Host
##end region Switch to Backup
#region DeclaringBackuplocation
$destination = Join-Path -Path “\server\share” -ChildPath $env:USERNAME
#endregion DeclaringBackuplocation
#region DeclaringDataBackupSources
$folder = “Desktop”,
#“Downloads”,
#“Favorites”,
“Documents”,
“Pictures”,
“Videos”,
“AppData\Roaming\Microsoft\Signatures”
#“AppData\Local\Google\Chrome\User Data\Default”
#endregion DeclaringDataBackupSources
#Backup Chrome bookmarks
#$chromeBookmarksPath = Join-Path -Path $env:USERPROFILE -ChildPath #“\AppData\Local\Google\Chrome\User Data\Default\Bookmarks.bak”
#$chromeBookmarks = Get-ChildItem $chromeBookmarksPath
#$chromeBookmarks
#$chromeBookmarks_DestinationPath = Join-Path $destination -ChildPath #"\AppData\Local\Google\Chrome\User Data\Default"
#“ChromeBookmarks_DestinationPath: $chromeBookmarks_DestinationPath”
#Copy-Item -Path $chromeBookmarks_DestinationPath -Destination $chromeBookmarks.BaseName
#Robocopy.exe /mir $chromeBookmarksPath $chromeBookmarks_DestinationPath
Backup Data section
Write-Host “”
Write-Host “”
Write-Host “”
Write-Host -ForegroundColor green “Backing up data from local machine for $env:USERNAME”
#region DataBackup
ForEach ($f in $folder) {
$currentLocalFolder = Join-Path -Path $env:USERPROFILE -ChildPath $f
$currentRemoteFolder = Join-Path -Path $destination -ChildPath $f
$currentFolderSize = (Get-ChildItem -ErrorAction silentlyContinue $currentLocalFolder -Recurse -Force | Measure-Object -ErrorAction silentlyContinue -Property Length -Sum ).Sum / 1MB
$currentFolderSizeRounded = [System.Math]::Round($currentFolderSize)
Write-Host -ForegroundColor cyan " $f... ($currentFolderSizeRounded MB)"
Copy-Item -Force -ErrorAction silentlyContinue -recurse $currentLocalFolder $currentRemoteFolder
}
#endregion DataBackup
Write-Host “”
Write-Host -ForegroundColor green “Registry Backup Complete”
#>
Write-Host “”
Write-Host “”
Write-Host -ForegroundColor green “Backup complete!”