-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunction_Copy_UserProfile.ps1
More file actions
62 lines (55 loc) · 1.89 KB
/
Function_Copy_UserProfile.ps1
File metadata and controls
62 lines (55 loc) · 1.89 KB
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
# Parameters: New computer, Old computer, and user profile name.
# USER MUST ALREADY HAVE PROFILE CREATED ON NEW COMPUTER
function Copy-UserProfile{
Param(
[String]$OldComputer,
[String]$NewComputer,
[String]$UserProfileName
)
# Test if Old computer available
if(Test-Connection -ComputerName $OldComputer -Quiet -Count 1){
Write-Host "$($OldComputer) found..." -ForegroundColor Green
}
else{
Write-Host "$($OldComputer) is not available" -ForegroundColor Red
Break
}
# Test if new computer available
if(Test-Connection -ComputerName $NewComputer -Quiet -Count 1){
Write-Host "$($NewComputer) found..." -ForegroundColor Green
}
else{
Write-Host "$($NewComputer) is not available" -ForegroundColor Red
Break
}
# Test if user profile exists on old computer
if(Test-Path \\$OldComputer\c$\Users\$UserProfileName){
Write-Host "$($UserProfileName) profile found..." -ForegroundColor Green
}
else{
Write-Host "$($UserProfileName) profile not found" -ForegroundColor Red
Break
}
$FoldersToCopy = @(
'Desktop'
'Downloads'
'Favorites'
'Documents'
'Pictures'
'Videos'
'AppData\Local\Google'
)
$SourceRoot = "\\$OldComputer\c$\Users\$UserProfileName"
$DestinationRoot = "\\$NewComputer\c$\Users\$UserProfileName"
foreach($Folder in $FoldersToCopy){
$Source = Join-Path -Path $SourceRoot -ChildPath $Folder
$Destination = Join-Path -Path $DestinationRoot -ChildPath $Folder
if( -not ( Test-Path -Path $Source -PathType Container)){
Write-Warning "Could not find path `t$Source"
continue
}
else{
Robocopy.exe $Source $Destination /E /IS /NP /NFL
}
}
}