-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMove-ProfileData.ps1
More file actions
149 lines (118 loc) · 5.7 KB
/
Move-ProfileData.ps1
File metadata and controls
149 lines (118 loc) · 5.7 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
function Move-ProfileData { # Start function
<#
.SYNOPSIS
Migrates data stored in an old windows user profile to a new profile
.DESCRIPTION
Copies data in the following directories to the new profile:
File explorer quick access items
Google Chrome data
MS Edge data
Mozilla Firefox data
OneNote Files (Everything)
OneNote "Backup" Files
Windows Credential Manager Objects
Outlook Signature content
Taskbar File location
Optionally: Outlook Data Files - use the IncludeOutlookData paramater
.PARAMETER ComputerName
Computer name of the machine that houses the profile data. Defaults to local hostname where script is ran from
.PARAMETER NewProfileName
New profile you're migrating data into
.PARAMETER OldProfileName
Old profile you're migrating data out of
.PARAMETER IncludeOutlookData
If $true is passed in outlook data files will be copied over to new profile. By default outlook data files will not be included in move
.EXAMPLE
Move-ProfileData -ComputerName "Shaneserver" -OldProfileName "oldprofile" -NewProfileName "newprofile" -IncludeOutlookData $False
.NOTES
Can be ran after Start-ProfileRebuild.ps1
#>
[CmdletBinding()]
Param (
[Parameter(ValueFromPipeline = $True, Mandatory = $False)]
[String]$ComputerName = $env:COMPUTERNAME,
[Parameter(Mandatory = $True)]
[String]$NewProfileName,
[Parameter(Mandatory = $True)]
[String]$OldProfileName,
[Parameter(Mandatory = $True)]
[Boolean]$IncludeOutlookData
)
begin {
$SourceProfileExists = Test-Path "C:\Users\$OldProfileName"
$DestinationProfileExists = Test-Path "C:\Users\$NewProfileName"
$TestCondition = (($SourceProfileExists) -and ($DestinationProfileExists))
}
process {
if ( $TestCondition ) {
$SourcePaths = @( # Source file locations
"C:\Users\$OldProfileName\Desktop\*"
"C:\Users\$OldProfileName\Downloads\*"
"C:\Users\$OldProfileName\Documents\*"
"C:\Users\$OldProfileName\Pictures\*"
"C:\Users\$OldProfileName\Videos\*"
"C:\Users\$OldProfileName\Appdata\Roaming\microsoft\windows\recent\automaticdestinations\*"
"C:\Users\$OldProfileName\AppData\Local\Google\Chrome\User Data\Default\*"
"C:\Users\$OldProfileName\AppData\Local\Microsoft\Edge\User Data\Default\*"
"C:\Users\$OldProfileName\AppData\Roaming\Mozilla\Firefox\Profiles\*"
"C:\Users\$OldProfileName\AppData\local\Mozilla\Firefox\Profiles\*"
"C:\Users\$OldProfileName\AppData\Roaming\Microsoft\Signatures\*"
"C:\Users\$OldProfileName\AppData\Local\Packages\Microsoft.Office.OneNote_8wekyb3d8bbwe\*"
"C:\Users\$OldProfileName\AppData\Local\Microsoft\OneNote\16.0\Backup\*"
"C:\Users\$OldProfileName\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*"
"C:\Users\$OldProfileName\AppData\Local\Microsoft\Vault\*"
)
$DestinationPaths = @(
"C:\Users\$NewProfileName\Desktop"
"C:\Users\$NewProfileName\Downloads"
"C:\Users\$NewProfileName\Documents"
"C:\Users\$NewProfileName\Pictures"
"C:\Users\$NewProfileName\Videos"
"C:\Users\$NewProfileName\Appdata\Roaming\microsoft\windows\recent\automaticdestinations"
"C:\Users\$NewProfileName\AppData\Local\Google\Chrome\User Data\Default"
"C:\Users\$NewProfileName\AppData\Local\Microsoft\Edge\User Data\Default"
"C:\Users\$NewProfileName\AppData\Roaming\Mozilla\Firefox\Profiles"
"C:\Users\$NewProfileName\AppData\local\Mozilla\Firefox\Profiles"
"C:\Users\$NewProfileName\AppData\Roaming\Microsoft\Signatures"
"C:\Users\$NewProfileName\AppData\Local\Packages\Microsoft.Office.OneNote_8wekyb3d8bbwe"
"C:\Users\$NewProfileName\AppData\Local\Microsoft\OneNote\16.0\Backup"
"C:\Users\$NewProfileName\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
"C:\Users\$NewProfileName\AppData\Local\Microsoft\Vault"
)
# Move-Item moves data into new profile programmatically
for ($i = 0; $i -lt $SourcePaths.Length; $i++) {
$SourcePath = $SourcePaths[$i]
$DestinationPath = $DestinationPaths[$i]
if ((Test-Path -Path $SourcePath) -and (Test-Path -Path $DestinationPath)) {
Move-Item -Path $SourcePath -Destination $DestinationPath -Force # Move all content in directory to new profile directory
}
else {
Write-Warning "Skipping directory $SourcePath as source or destination directory doesn't exist"
}
} # End for loop
} # End if statement
elseif ( $TestCondition = $False ) {
if ( $SourceProfileExists -eq $False ) {
Write-Warning "Error - Source profile path C:\Users\$OldProfileName doesn't exist"
Write-Warning "Double check the source profile name"
}
if ( $DestinationProfileExists -eq $False ) {
Write-Warning "Error - Destination profile path C:\Users\$NewProfileName doesn't exist"
Write-Warning "Re-run script after logging in with user credentials to create the new profile if it doesn't exist"
}
} # End elseif
# Move-Item moves data for outlook data files if the $True boolean value is passed in via the IncludeOutlookData parameter
if ( $IncludeOutlookData -eq $True ) {
$OutlookSource = "C:\Users\$OldProfileName\AppData\Local\Microsoft\Outlook\*"
$OutlookDestination = "C:\Users\$NewProfileName\AppData\Local\Microsoft\Outlook"
$OutlookSourceExists = Test-Path -Path $OutlookSource
$OutlookDestinationExists = Test-Path -Path $OutlookDestination
if (($OutlookSourceExists) -and ($OutlookDestinationExists)) {
Move-Item -Path "C:\Users\$OldProfileName\AppData\Local\Microsoft\Outlook\*" -Destination "C:\Users\$NewProfileName\AppData\Local\Microsoft\Outlook" -Force
}
else {
Write-Warning "Directory skipped - Outlook OST source file path $OutlookSource or destination file path $OutlookDestination doesn't exist"
}
} # End if statement
} # End process block
} # End function