Skip to content

Commit 55b026c

Browse files
Nick RodriguezNick Rodriguez
Nick Rodriguez
authored and
Nick Rodriguez
committed
Add script to aid in expanding .MIG files.
1 parent 9460d93 commit 55b026c

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

Expand-UsmtMig.ps1

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[CmdletBinding()]
2+
3+
param(
4+
[Parameter(Mandatory = $false)]
5+
[ValidateScript( {
6+
if ((Get-Item $_).Extension -ne '.MIG') {
7+
throw "[$_] is not a USMT migration file (mig)."
8+
}
9+
else { $true }
10+
})]
11+
[string]$MigPath
12+
)
13+
14+
$CurrentID = [System.Security.Principal.WindowsIdentity]::GetCurrent()
15+
$WindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($CurrentID)
16+
$AdminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator
17+
18+
if (-not $WindowsPrincipal.IsInRole($AdminRole)) {
19+
$NewProcess = New-Object System.Diagnostics.ProcessStartInfo 'PowerShell'
20+
$NewProcess.Arguments = $MyInvocation.MyCommand.Definition
21+
$NewProcess.Verb = 'RunAs'
22+
[System.Diagnostics.Process]::Start($NewProcess)
23+
24+
exit
25+
}
26+
27+
# Get USMT binary path according to OS architecture
28+
$arch = (Get-WmiObject Win32_OperatingSystem).OSArchitecture
29+
if ($arch -match '64') {
30+
$usmtPath = "$PSScriptRoot\USMT\amd64"
31+
} elseif ($arch -match '86') {
32+
$usmtPath = "$PSScriptRoot\USMT\x86"
33+
}
34+
else {
35+
$usmtPath = "$PSScriptRoot\USMT\arm64"
36+
}
37+
38+
if ([string]::IsNullOrEmpty($MigPath)) {
39+
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
40+
41+
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
42+
$OpenFileDialog.Title = "Select a USMT migration file to expand"
43+
$OpenFileDialog.Filter = "MIG (*.MIG)| *.MIG"
44+
$OpenFileDialog.ShowHelp = $true
45+
$OpenFileDialog.ShowDialog() | Out-Null
46+
$MigPath = Get-Item $OpenFileDialog.FileName
47+
}
48+
49+
$destination = Split-Path $MigPath -Parent
50+
51+
try {
52+
Start-Process -FilePath "$usmtPath\usmtutils.exe" -ArgumentList "/extract `"$MigPath`" `"$destination`"" -Wait -NoNewWindow
53+
}
54+
catch {
55+
Write-Host $_.Exception.Message -ForegroundColor Red
56+
}
57+
58+
pause

0 commit comments

Comments
 (0)