1+ # Verify Running as Admin
2+ $isAdmin = ([Security.Principal.WindowsPrincipal ] [Security.Principal.WindowsIdentity ]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole ] " Administrator" )
3+ If (-not $isAdmin ) {
4+ Write-Host " -- Restarting as Administrator" - ForegroundColor Cyan ; Start-Sleep - Seconds 1
5+
6+ if ($PSVersionTable.PSEdition -eq " Core" ) {
7+ Start-Process pwsh.exe " -NoProfile -ExecutionPolicy Bypass -File `" $PSCommandPath `" " - Verb RunAs
8+ } else {
9+ Start-Process powershell.exe " -NoProfile -ExecutionPolicy Bypass -File `" $PSCommandPath `" " - Verb RunAs
10+ }
11+ exit
12+ }
13+
14+ $folder = $PSScriptRoot
15+ # $folder="c:\temp"
16+
17+ [reflection.assembly ]::loadwithpartialname(" System.Windows.Forms" )
18+ $openFiles = New-Object System.Windows.Forms.OpenFileDialog - Property @ {
19+ Multiselect = $true ;
20+ Title = " Please select msix file(s)"
21+ }
22+ $openFiles.Filter = " msix files (*.msix)|*.msix"
23+
24+
25+ If ($openFiles.ShowDialog () -eq " OK" ){
26+ Write-Host " Selected Files:" - ForegroundColor Cyan
27+ foreach ($filename in $openFiles.Filenames ){
28+ Write-Host " `t $FileName " - ForegroundColor Cyan
29+ }
30+ }
31+
32+ # Download MSIX Image tool if not available"
33+ if (! (Test-Path " $folder \msixmgr\x64\msixmgr.exe" )){
34+ Invoke-WebRequest - Uri https:// aka.ms/ msixmgr - OutFile " $folder \msixmgr.zip"
35+ Expand-Archive - Path " $folder \msixmgr.zip" - DestinationPath " $folder \msixmgr"
36+ }
37+
38+ foreach ($File in $openFiles.FileNames ){
39+ $appname = ($file | Split-Path - Leaf).TrimEnd(" .msix" )
40+ if (! (test-path - Path $folder )){
41+ New-Item - Path $folder - ItemType Directory
42+ }
43+ $vhd = New-VHD - SizeBytes 100 GB - path $folder \$appname.vhdx - dynamic - confirm:$false
44+ # mount and format VHD
45+ $VHDMount = Mount-VHD $vhd.Path - Passthru
46+ $vhddisk = $vhdmount | Get-Disk
47+ $vhddiskpart = $vhddisk | Initialize-Disk - PartitionStyle GPT - PassThru | New-Partition - UseMaximumSize - AssignDriveLetter | Format-Volume - Filesystem NTFS - AllocationUnitSize 8 kb - NewFileSystemLabel $appname
48+
49+ Start-Process - FilePath " $folder \msixmgr\x64\msixmgr.exe" - ArgumentList " -Unpack -packagePath `" $File `" -destination $ ( $vhddiskpart.driveletter ) :\ -applyacls" - Wait
50+
51+ Dismount-VHD $vhddisk.number
52+ }
53+
54+ Read-Host " job done. Press enter to exit"
55+
0 commit comments