-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserProfileFolderRestoration-withExclustions.ps1
64 lines (54 loc) · 2.51 KB
/
userProfileFolderRestoration-withExclustions.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Prompt for source PC, destination PC, and user to restore
$sourcePC = Read-Host "Enter source PC name or IP address"
$destinationPC = Read-Host "Enter destination PC name or IP address"
$userToRestore = Read-Host "Enter the user to restore"
# Normalize input to lowercase
$userToRestore = $userToRestore.ToLower()
# Define source and destination paths
$sourceBackupPath = "\\$sourcePC\C$\$userToRestore-BACKUP\$userToRestore"
$destinationPath = "\\$destinationPC\C$\Users\$userToRestore"
# Define files and directories to exclude
$excludeList = @(
"*ntuser.dat*", # Exclude ntuser.dat files
"*config*", # Exclude configuration files
"*database*", # Exclude database files
"*system*", # Exclude system files
"*Temp*", # Exclude Temp folder
"*Cache*", # Exclude Cache folder
"NTUSER.DAT*", # Exclude NTUSER.DAT files
"UsrClass.dat*", # Exclude UsrClass.dat files
"Desktop.ini", # Exclude Desktop.ini file
"Thumbs.db", # Exclude Thumbs.db file
"AppData\Local\Temp", # Exclude Temp folder in AppData\Local
"AppData\Roaming\Microsoft\Windows\Recent" # Exclude Recent folder
)
# Remove Chrome and Edge directories from the exclusion list
$excludeList = $excludeList | Where-Object { $_ -notlike "AppData\Local\Google\Chrome*" -and $_ -notlike "AppData\Local\Packages\Microsoft.MicrosoftEdge*" }
# Function to move files and folders using robocopy
function Move-UserFiles {
param (
[string]$source,
[string]$destination
)
robocopy "$source" "$destination" /E /COPYALL /XD $excludeList /R:0 /W:0 /XO
}
# Validate source and destination paths
if (-not (Test-Path $sourceBackupPath)) {
Write-Host "Source backup path '$sourceBackupPath' not found or inaccessible. Please check the path and try again."
exit
}
if (-not (Test-Path $destinationPath)) {
Write-Host "Destination path '$destinationPath' not found or inaccessible. Please check the path and try again."
exit
}
# Confirm details before proceeding
Write-Host "Source PC: $sourcePC"
Write-Host "Destination PC: $destinationPC"
Write-Host "User to restore: $userToRestore"
$confirm = Read-Host "Confirm the details above and proceed? (Y/N)"
if ($confirm -ne "Y") {
Write-Host "Operation aborted."
exit
}
# Move user data to the new profile preserving permissions and structure
Move-UserFiles -source $sourceBackupPath -destination $destinationPath