-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMigration.ps1
More file actions
378 lines (298 loc) · 15 KB
/
Migration.ps1
File metadata and controls
378 lines (298 loc) · 15 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#############################################################
# 1. Save as: Migration.ps1 #
# 2. Open PowerShell as Admin. #
# 3. Run: Set-ExecutionPolicy RemoteSigned -Scope Process #
# 4. Run: cd ~\Desktop; .\Migration.ps1 #
#############################################################
#################
# Configuration #
#################
$backupRoot = "E:\Backups"
$logFile = "$backupRoot\Backup_Log.txt"
if (!(Test-Path $backupRoot)) {
New-Item -ItemType Directory -Path $backupRoot -Force | Out-Null
}
"--- Backup Log Started: $(Get-Date) ---" | Out-File -FilePath $logFile
##########################
# Verify Windows Version #
##########################
Write-Host "Checking Windows System Details..." -ForegroundColor "Magenta" -BackgroundColor "Black"
$sysInfo = Get-ComputerInfo -Property OsName, WindowsBuildLabEx, WindowsProductName
$osDetails = @"
OS Name: $($sysInfo.OsName)
Product Name: $($sysInfo.WindowsProductName)
Build Lab Ex: $($sysInfo.WindowsBuildLabEx)
"@
$osDetails | Out-File -FilePath "$backupRoot\OS_Version.txt"
$osDetails | Out-File -FilePath $logFile -Append
############################
# Install Revo Uninstaller #
############################
Write-Host "Installing Revo Uninstaller..." -ForegroundColor "Magenta" -BackgroundColor "Black"
winget install RevoUninstaller.RevoUninstaller --silent --accept-package-agreements --source winget 2>$null
#################################
# Verify Local Users and Groups #
#################################
Get-LocalUser | Export-Csv -Path "$backupRoot\LocalUsers.csv"
Get-LocalGroup | ForEach-Object {
$groupName = $_.Name
Get-LocalGroupMember -Group $groupName | Select-Object @{N="Group";E={$groupName}}, Name, PrincipalSource
} | Export-Csv -Path "$backupRoot\GroupMembers.csv"
###############################
# Copy Windows Activation Key #
###############################
$key = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform").BackupProductKeyDefault
$key | Out-File -FilePath "$backupRoot\WindowsKey.txt"
################################
# Screenshot Desktop #
# Tips: move your open windows #
################################
Add-Type -AssemblyName System.Windows.Forms, System.Drawing
$screen = [System.Windows.Forms.Screen]::PrimaryScreen
$bitmap = New-Object System.Drawing.Bitmap $screen.Bounds.Width, $screen.Bounds.Height
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
$graphic.CopyFromScreen($screen.Bounds.X, $screen.Bounds.Y, 0, 0, $bitmap.Size)
$bitmap.Save("$backupRoot\screenshotDesktop.png", [System.Drawing.Imaging.ImageFormat]::Png)
####################################
# Backup current desktop wallpaper #
####################################
$wallpaperSource = "$env:APPDATA\Microsoft\Windows\Themes\TranscodedWallpaper"
$backupDirectory = "E:\Backups\Wallpapers"
$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
$destinationFile = Join-Path $backupDirectory "Wallpaper_Backup_$($timestamp).jpg"
if (!(Test-Path $backupDirectory)) {
New-Item -ItemType Directory -Path $backupDirectory | Out-Null
Write-Host "Created backup folder at $backupDirectory" -ForegroundColor "Magenta" -BackgroundColor "Black"
}
if (Test-Path $wallpaperSource) {
Copy-Item -Path $wallpaperSource -Destination $destinationFile
Write-Host "Success! Wallpaper backed up to: $destinationFile" -ForegroundColor "Green" -BackgroundColor "Black"
} else {
Write-Warning "Could not find the current wallpaper file. You might be using a solid color." -ForegroundColor "Red" -BackgroundColor "Black"
}
################################
# Backup Icons Position Layout #
################################
$backupLoc = "E:\Backups\DesktopLayouts"
$timestamp = Get-Date -Format "yyyy-MM-dd_HHmm"
$backupFile = "$backupLoc\DesktopLayout_$timestamp.reg"
if (!(Test-Path $backupLoc)) {
New-Item -ItemType Directory -Path $backupLoc | Out-Null
Write-Host "Created backup directory at $backupLoc" -ForegroundColor "Magenta" -BackgroundColor "Black"
}
$registryPath = "HKCU\Software\Microsoft\Windows\Shell\Bags\1\Desktop"
try {
reg export $registryPath "$backupFile" /y
Write-Host "Success! Desktop layout backed up to: $backupFile" -ForegroundColor "Green" -BackgroundColor "Black"
}
catch {
Write-Host "Error: Could not export registry key. Ensure you have proper permissions." -ForegroundColor "Red" -BackgroundColor "Black"
}
############################
# Backup User Profile Data #
############################
$userProfileDest = "$backupRoot\UserProfiles"
$activeUsers = Get-ChildItem "C:\Users" | Where-Object { $_.Name -notmatch "Public|Administrator|Default" }
$userCount = 0
foreach ($userProfile in $activeUsers) {
$userCount++
$userName = $userProfile.Name
$userPath = $userProfile.FullName
$destPath = "$userProfileDest\$userName"
Write-Progress -Activity "Backing up User Profiles" -Status "Processing: $userName" -PercentComplete (($userCount / $activeUsers.Count) * 100)
New-Item -ItemType Directory -Force -Path $destPath | Out-Null
###################################
# Copy Folders with Error Logging #
###################################
$folders = "Documents", "Pictures", "Music", "Downloads", "Videos", "Contacts", "Desktop"
foreach ($f in $folders) {
if (Test-Path "$userPath\$f") {
try {
Copy-Item -Path "$userPath\$f" -Destination $destPath -Recurse -Force -ErrorAction Stop
"SUCCESS: Copied $f for $userName" | Out-File -FilePath $logFile -Append
} catch {
"ERROR: Failed to copy $f for $userName. Reason: $($_.Exception.Message)" | Out-File -FilePath $logFile -Append
}
}
}
###########################
# Chrome Bookmarks Backup #
###########################
$chromePath = "$env:USERPROFILE\AppData\Local\Google\Chrome\User Data\Default\Bookmarks"
$backupFolder = "E:\Backups\ChromeBookmarks"
$timestamp = Get-Date -Format "yyyy-MM-dd_HHmm"
$destinationPath = "$backupFolder\Bookmarks_Backup_$timestamp"
if (!(Test-Path $backupFolder)) {
New-Item -ItemType Directory -Path $backupFolder | Out-Null
}
if (Test-Path $chromePath) {
Copy-Item -Path $chromePath -Destination $destinationPath
Write-Host "Success! Bookmarks backed up to: $destinationPath" -ForegroundColor "Green" -BackgroundColor "Black"
} else {
Write-Warning "Chrome bookmarks file not found at the default location." -ForegroundColor "Red" -BackgroundColor "Black"
Write-Host "Note: If you use multiple Chrome profiles, the path may be different (e.g., 'Profile 1' instead of 'Default')." -ForegroundColor "Cyan" -BackgroundColor "Black"
}
#########################
# Edge Bookmarks Backup #
#########################
$edgePath = "$env:LOCALAPPDATA\Microsoft\Edge\User Data\Default\Bookmarks"
$backupDir = "E:\Backups\EdgeBookmarks"
$timestamp = Get-Date -Format "yyyy-MM-dd_HHmm"
$destination = "$backupDir\Bookmarks_$timestamp.bak"
if (!(Test-Path $backupDir)) {
New-Item -ItemType Directory -Path $backupDir | Out-Null
Write-Host "Created backup directory at $backupDir" -ForegroundColor "Magenta" -BackgroundColor "Black"
}
if (Test-Path $edgePath) {
Copy-Item -Path $edgePath -Destination $destination -Force
Write-Host "Success! Edge bookmarks backed up to: $destination" -ForegroundColor "Green" -BackgroundColor "Black"
} else {
Write-Warning "Edge Bookmarks file not found at $edgePath. Do you have a Profile other than 'Default'?" -ForegroundColor "Red" -BackgroundColor "Black"
}
############################
# Firefox Bookmarks Backup #
############################
$FirefoxProfilePath = "$env:APPDATA\Mozilla\Firefox\Profiles"
$BackupDest = "E:\Backups\FirefoxBookmarks"
if (!(Test-Path $BackupDest)) {
New-Item -ItemType Directory -Path $BackupDest | Out-Null
}
$ProfileFolder = Get-ChildItem -Path $FirefoxProfilePath | Where-Object { $_.Name -like "*.default*" } | Select-Object -First 1
if ($ProfileFolder) {
$SourceFile = Join-Path $ProfileFolder.FullName "places.sqlite"
$Timestamp = Get-Date -Format "yyyy-MM-dd_HHmm"
$DestinationFile = Join-Path $BackupDest "bookmarks_backup_$Timestamp.sqlite"
if (Test-Path $SourceFile) {
# Copy the file
Copy-Item -Path $SourceFile -Destination $DestinationFile -Force
Write-Host "Success! Bookmarks backed up to: $DestinationFile" -ForegroundColor "Green" -BackgroundColor "Black"
} else {
Write-Error "Could not find places.sqlite in the profile folder." -ForegroundColor "Red" -BackgroundColor "Black"
}
} else {
Write-Error "Firefox profile folder not found." -ForegroundColor "Red" -BackgroundColor "Black"
}
##########################
# Verify Office Version #
##########################
Write-Host "Checking Office Version..." -ForegroundColor "Magenta" -BackgroundColor "Black"
$officeVersion = "Not Found"
$paths = @(
"HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration",
"HKLM:\SOFTWARE\Microsoft\Office\16.0\Outlook",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Office\16.0\Outlook"
)
foreach ($path in $paths) {
if (Test-Path $path) {
$versionInfo = Get-ItemProperty -Path $path -ErrorAction SilentlyContinue
if ($versionInfo.VersionToReport) {
$officeVersion = $versionInfo.VersionToReport
} elseif ($versionInfo.Bitness) {
$officeVersion = "Office 16.0 ($($versionInfo.Bitness))"
}
}
}
"Office Version: $officeVersion" | Out-File -FilePath "$backupRoot\Office_Info.txt"
"Office Version: $officeVersion" | Out-File -FilePath $logFile -Append
###############################
# Office Activation Status #
###############################
Write-Host "Retrieving Office License Info..." -ForegroundColor "Magenta" -BackgroundColor "Black"
###########################################
# Search for the OSPP.VBS script location #
###########################################
$osppPath = Get-ChildItem -Path "C:\Program Files\Microsoft Office", "C:\Program Files (x86)\Microsoft Office" -Filter "ospp.vbs" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
if ($osppPath) {
$status = cscript "$($osppPath.FullName)" /dstatus
$status | Out-File -FilePath "$backupRoot\Office_Info.txt" -Append
"SUCCESS: Exported Office license status to Office_Info.txt" | Out-File -FilePath $logFile -Append
} else {
"ERROR: ospp.vbs not found. Could not retrieve Office key info." | Out-File -FilePath $logFile -Append
}
###############################
# Ensure Sage 50 is Closed #
###############################
Write-Host "Checking for running Sage 50 processes..." -ForegroundColor "Magenta" -BackgroundColor "Black"
$sageProcesses = @("Sage50Accounting", "Peachw", "SmartDesktop.UI")
foreach ($proc in $sageProcesses) {
$running = Get-Process -Name $proc -ErrorAction SilentlyContinue
if ($running) {
Write-Host "Closing $proc..." -ForegroundColor "Red" -BackgroundColor "Black"
Stop-Process -Name $proc -Force
Start-Sleep -Seconds 2
}
}
"INFO: Checked and closed Sage 50 processes before backup." | Out-File -FilePath $logFile -Append
###############################
# Copy Sage 50 Activation Key #
###############################
Write-Host "Retrieving Sage 50 License Info..." -ForegroundColor "Magenta" -BackgroundColor "Black"
$sageRegPath = "HKLM:\SOFTWARE\WOW6432Node\Sage Software\Simply Accounting"
if (Test-Path $sageRegPath) {
$sageVersions = Get-ChildItem $sageRegPath
$sageLicenseInfo = foreach ($ver in $sageVersions) {
$registration = Get-ItemProperty -Path "$($ver.PSPath)\Registration" -ErrorAction SilentlyContinue
if ($registration) {
"Version: $($ver.PSChildName)`nSerial: $($registration.SerialNumber)`nAccount ID: $($registration.AccountID)`n"
}
}
$sageLicenseInfo | Out-File -FilePath "$backupRoot\Sage50_Keys.txt"
"SUCCESS: Exported Sage 50 License info." | Out-File -FilePath $logFile -Append
} else {
"WARNING: Sage 50 registry path not found." | Out-File -FilePath $logFile -Append
}
#######################
# Backup Sage 50 Data #
#######################
Write-Host "Searching for Sage 50 Data (.sai/.saj)..." -ForegroundColor "Magenta" -BackgroundColor "Black"
$sageBackupDir = "$backupRoot\Sage50Data"
if (!(Test-Path $sageBackupDir)) { New-Item -ItemType Directory -Path $sageBackupDir -Force | Out-Null }
$searchPaths = @("C:\Sage50Data", "$userPath\Documents")
foreach ($path in $searchPaths) {
if (Test-Path $path) {
# Find all .sai files (the connector file)
$saiFiles = Get-ChildItem -Path $path -Filter "*.sai" -Recurse -ErrorAction SilentlyContinue
foreach ($sai in $saiFiles) {
try {
# Copy the .sai file
Copy-Item $sai.FullName -Destination $sageBackupDir -Force
# Copy the corresponding .saj folder (which contains the actual database)
$sajPath = $sai.FullName.Replace(".sai", ".saj")
if (Test-Path $sajPath) {
Copy-Item $sajPath -Destination $sageBackupDir -Recurse -Force
}
"SUCCESS: Backed up Sage Company: $($sai.Name)" | Out-File -FilePath $logFile -Append
} catch {
"ERROR: Failed to copy Sage data $($sai.Name). Ensure Sage is closed." | Out-File -FilePath $logFile -Append
}
}
}
}
###############################
# Ensure Outlook is Closed #
###############################
Write-Host "Checking for running Outlook processes..." -ForegroundColor "Magenta" -BackgroundColor "Black"
$outlookProc = Get-Process -Name "Outlook" -ErrorAction SilentlyContinue
if ($outlookProc) {
Write-Host "Closing Outlook to unlock data files..." -ForegroundColor "Yellow" -BackgroundColor "Black"
Stop-Process -Name "Outlook" -Force
Start-Sleep -Seconds 3
"INFO: Closed Outlook process before backup." | Out-File -FilePath $logFile -Append
} else {
"INFO: Outlook was not running." | Out-File -FilePath $logFile -Append
}
#######################
# Backup Outlook PSTs #
#######################
Get-ChildItem -Path $userPath -Filter "*.pst" -Recurse -ErrorAction SilentlyContinue | ForEach-Object {
try {
Copy-Item $_.FullName -Destination $destPath -Force -ErrorAction Stop
"SUCCESS: Copied PST: $($_.Name)" | Out-File -FilePath $logFile -Append
} catch {
"ERROR: Could not copy PST $($_.Name). It may be open." | Out-File -FilePath $logFile -Append
}
}
}
Read-Host -Prompt "Press Enter to finish and open the backup folder"
Write-Host "`nAll operations completed. Check Backup_Log.txt for details." -ForegroundColor "Cyan" -BackgroundColor "Black"
Invoke-Item "E:\Backups"