$volume = Get-Disk | Where Number -eq $disk |
New-Partition -UseMaximumSize -AssignDriveLetter |
Format-Volume -FileSystem FAT32
[], RuntimeException# Tamaño minimo del pen USB stick 5.29GB
# Poner aquí donde tenemos el ISO de W2016
$iso = 'C:\Users\localuser\Downloads\en_windows_server_2016_x64_dvd_9327751.iso'
# Limpiar el USB. [COLOR=#FF0000][B]Poner en NN en la linea inferior el Numero de Disco del Pen que se ve en DISKPART[/B][/COLOR]
# [U][B][COLOR=#FF0000]Ser cuidadoso con esto o borraremos un disco que no procede.[/COLOR][/B][/U]
$disk=[SIZE=14px][B][COLOR=#FF0000]NN[/COLOR][/B][/SIZE]
Get-Disk | Where Number -eq $disk | Clear-Disk -RemoveData -Confirm:$true -PassThru
# Convertir a GPT
if ((Get-Disk | Where Number -eq $disk).PartitionStyle -eq 'RAW') {
Get-Disk | Where Numer -eq $disk |
Initialize-Disk -PartitionStyle GPT
} else {
Get-Disk | Where Number -eq $disk |
Set-Disk -PartitionStyle GPT
}
# Crear partition primaria y format a FAT32
$volume = Get-Disk | Where Number -eq $disk |
New-Partition -UseMaximumSize -AssignDriveLetter |
Format-Volume -FileSystem FAT32
if (Test-Path -Path "$($volume.DriveLetter):\") {
# Mount iso
$miso = Mount-DiskImage -ImagePath $iso -StorageType ISO -PassThru
# Driver letter
$dl = ($miso | Get-Volume).DriveLetter
}
if (Test-Path -Path "$($dl):\sources\install.wim") {
# Copiar ISO excepto el install.wim
& (Get-Command "$($env:systemroot)\system32\robocopy.exe") @(
"$($dl):\",
"$($volume.DriveLetter):\"
,'/S','/R:0','/Z','/XF','install.wim','/NP'
)
# Trocear el install.wim
& (Get-Command "$($env:systemroot)\system32\dism.exe") @(
'/split-image',
"/imagefile:$($dl):\sources\install.wim",
"/SWMFile:$($volume.DriveLetter):\sources\install.swm",
'/FileSize:4096'
)
}
# Eject USB
(New-Object -comObject Shell.Application).NameSpace(17).
ParseName("$($volume.DriveLetter):").InvokeVerb('Eject')
# Dismount ISO
Dismount-DiskImage -ImagePath $iso
Dejar un comentario: