Forked from p0w3rsh3ll/WS2016-UEFI-USB-boot-stick.ps1
Last active
February 23, 2019 00:21
-
-
Save apharp/6ca7703965dbea5a71e73b118afd34af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# minimum size of USB stick 5.29GB | |
# Set here the path of your ISO file | |
$iso = "C:\path\to\Downloads\ISO\Server 2016\en_windows_server_2016_x64_dvd_9718492.iso" | |
# Clean ! will clear any plugged-in USB stick!! | |
Get-Disk | Where BusType -eq 'USB' | | |
Clear-Disk -RemoveData -Confirm:$true -PassThru | |
# Convert GPT | |
if ((Get-Disk | Where BusType -eq 'USB').PartitionStyle -eq 'RAW') { | |
Get-Disk | Where BusType -eq 'USB' | | |
Initialize-Disk -PartitionStyle MBR | |
} else { | |
Get-Disk | Where BusType -eq 'USB' | | |
Set-Disk -PartitionStyle MBR | |
} | |
# Create partition primary and format to FAT32 | |
$volume = Get-Disk | Where BusType -eq 'USB' | |
if ($volume.Size -gt "34347155456") { | |
$volume | New-Partition -Size 32GB -AssignDriveLetter | | |
Format-Volume -FileSystem FAT32 | |
} | |
else { | |
$volume | New-Partition -UseMaximumSize -AssignDriveLetter | | |
Format-Volume -FileSystem FAT32 | |
} | |
$voldl = ($volume | Get-Partition).DriveLetter | |
if (Test-Path -Path "$($voldl):\") { | |
# Mount iso | |
$miso = Mount-DiskImage -ImagePath $iso -StorageType ISO -PassThru | |
# Driver letter | |
$dl = ($miso | Get-Volume).DriveLetter | |
} | |
cmd /c "cd $($dl):\boot && bootsect.exe /nt60 $($voldl):" | |
if (Test-Path -Path "$($dl):\sources\install.wim") { | |
# Copy ISO content to USB except install.wim | |
& (Get-Command "$($env:systemroot)\system32\robocopy.exe") @( | |
"$($dl):\", | |
"$($voldl):\" | |
,'/S','/R:0','/Z','/XF','install.wim','/NP' | |
) | |
# Split install.wim | |
& (Get-Command "$($env:systemroot)\system32\dism.exe") @( | |
'/split-image', | |
"/imagefile:$($dl):\sources\install.wim", | |
"/SWMFile:$($voldl):\sources\install.swm", | |
'/FileSize:4096' | |
) | |
} | |
# Eject USB | |
(New-Object -comObject Shell.Application).NameSpace(17). | |
ParseName("$($voldl):").InvokeVerb('Eject') | |
# Dismount ISO | |
Dismount-DiskImage -ImagePath $iso |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forked from https://gist.github.com/p0w3rsh3ll/9106e3dc1bd2023ee5afd8cd85054613.
USAGE
To install WS2016 on a MacMini. I has issues with audio when I booted UEFI so I changed it to MBR and the issue resolved.
Changes
Changed boot form UEFI to MBR
Limited volume size to 32GB on larger capacity USB sticks.