Here is one of my "old" scripts (just deleted the echo statements and changed some variable names) : Spoiler Code: <# : standard way of doing hybrid batch + powershell scripts @set "__CMD__=%~f0" &set "__ARGS__=%*" &powershell -noprofile -c "iex([io.file]::ReadAllText(\"%~f0\"))" &exit/b #> # # This script must be executed with admin privilege # # Test Administrator privileges If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { # Restart the script to get Administrator privileges and exit Start-Process 'powershell.exe' -Verb runAs -ArgumentList ("-NoLogo -WindowStyle Normal -noprofile -file " + """" + $PSCommandPath + """") exit } # We have Administrator privileges # $pswindow = $host.ui.rawui # create a reference to the console’s UI.RawUI child object $newsize = $pswindow.buffersize # set the buffer size $newsize.height = 3000 # 3000 lines $newsize.width = 150 # 150 characters $pswindow.buffersize = $newsize # set the BufferSize properties $newsize = $pswindow.buffersize # assign the BufferSize properties to a variable named $newsize $pswindow.buffersize = $newsize # assign the values to the actual console window $newsize = $pswindow.windowsize # set the window size $newsize.height = [Math]::Min(50, $host.ui.rawui.MaxWindowSize.height) $newsize.width = [Math]::Min(150, $host.ui.rawui.MaxWindowSize.Width) $pswindow.windowsize = $newsize $pswindow.windowtitle = "Create USB boot disk" $pswindow.foregroundcolor = "Yellow";$pswindow.backgroundcolor = "Blue" # Add-Type -AssemblyName System.Windows.Forms # Load the class System.Windows.Forms # Filebrowser dialog $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{ Multiselect = $false # One file can be chosen Filter = 'ISO images (*.iso)|*.iso' # Select iso files title="Select the .iso image" } # Function ErrorMessage { Param([string]$msg) Write-Host -NoNewline $msg -ForegroundColor Red -backgroundColor White $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null $HOST.UI.RawUI.Flushinputbuffer() } clear-host $wshell=New-Object -ComObject Wscript.Shell # Select the USB stick $form=New-Object System.Windows.Forms.Form # Create the screen form (window) # $Form.ControlBox = $false $Form.FormBorderStyle = "none" $form.Text="Available USB disk(s)" $Form.Width=640 ; $Form.Height=300 $Form.backColor="LightYellow" $Form.AutoSize=$false $Form.startposition = "Manual" $form.Location=New-Object System.Drawing.Point(10,10) $USBDiskList=New-Object System.Windows.Forms.ComboBox $USBDiskList.DropDownStyle=[System.Windows.Forms.ComboBoxStyle]::DropDownList; $USBDiskList.Location=New-Object System.Drawing.Point(5,20) $USBDiskList.Width=630;$USBDiskList.height=20 # $USBDiskList.backColor="blue" ; $USBDiskList.ForeColor="White" $USBDiskList.Font='Courier New,10' $Form.KeyPreview = $True $Form.Add_KeyDown({if ($_.KeyCode -eq "Enter"){$OKButton.PerformClick()}}) $Form.Add_KeyDown({if ($_.KeyCode -eq "Escape"){$CancelButton.PerformClick()}}) $OKButton=New-Object System.Windows.Forms.Button # Put the OK button on the form $OKButton.Location=New-Object System.Drawing.Size(560,200) $OKButton.Text="OK";$OKButton.Font='Microsoft Sans Serif,10' $OKButton.width=60;$OKButton.height=30; $OKButton.Add_MouseHover({$OKButton.backcolor = [System.Drawing.Color]::CornflowerBlue}) $OKButton.Add_MouseLeave({$OKButton.backcolor = [System.Drawing.Color]::LightYellow}) $form.Controls.Add($OKButton) $OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK $CancelButton=New-Object System.Windows.Forms.Button # Put the Cancel button on the form $CancelButton.Location=New-Object System.Drawing.Size(460,200) $CancelButton.Text="Cancel";$CancelButton.Font='Microsoft Sans Serif,10' $CancelButton.width=60;$CancelButton.height=30; $CancelButton.Add_MouseHover({$CancelButton.backcolor = [System.Drawing.Color]::CornflowerBlue}) $CancelButton.Add_MouseLeave({$CancelButton.backcolor = [System.Drawing.Color]::LightYellow}) $form.Controls.Add($CancelButton) $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel $Label = New-Object System.Windows.Forms.label $Label.AutoSize = $True $Label.Location = new-object System.Drawing.Size(20,60) $Label.Size = New-Object System.Drawing.Size(150,20) $Label.BorderStyle = "None" $Label.Font = "Arial,10" # $Label.backColor="blue" ; $Label.ForeColor="White" $form.Controls.Add($Label) $USB=$Null $USBDisks=@() # array whith USB disk number $Disks=Get-Disk | Where-Object {($_.BusType -eq "USB") -and ($_.OperationalStatus -eq "Online")} While (!$Disks) { $Label.BorderStyle = "Fixed3D" $Label.Text="Please mount USB stick. Click ""OK"" when ready`r`nor ""Cancel"" to exit." $result = $form.ShowDialog() if ($result -eq "Cancel"){exit} $Disks=Get-Disk | Where-Object {($_.BusType -eq "USB") -and ($_.OperationalStatus -eq "Online")} } Foreach ($USBDisk in $Disks) { $FriendlyName=($USBDisk.FriendlyName).PadRight(30," ").substring(0,30) $Partitions = Get-Partition | Where-Object { $_.DiskNumber -eq $USBDisk.DiskNumber} If ($Partitions) { Foreach ($Partition in $Partitions) { $Volumes=get-volume | Where-Object {$Partition.AccessPaths -contains $_.path } Foreach ($Volume in $Volumes) { $USBDisks+=$USBDisk.DiskNumber $USBDiskList.Items.Add((" {0,-30}|{1,1}:| {2,-30}| {3:n2} GB" -f $FriendlyName, ($Partition.DriveLetter), $Volume.FileSystemLabel.PadRight(30," ").substring(0,30), ($Partition.Size/1GB)))|out-null } } } Else { $USBDisks+=$USBDisk.DiskNumber $USBDiskList.Items.Add((" {0,-30}| {1,1}| {2,-30}| {3:n2} GB" -f $FriendlyName, " ", " ",($USBDisk.Size/1GB)))|out-null } } $form.Controls.Add($USBDiskList) $USBDiskList.SelectedIndex=0 $Label.BorderStyle = "Fixed3D" $Label.Text="Select your device and click ""OK""`r`nor ""Cancel"" to exit." $result = $form.ShowDialog() if ($result -eq "Cancel"){exit} $USB=$USBDisks[$USBDiskList.SelectedIndex] # Clear the USB stick Clear-Disk $usb -RemoveData -RemoveOEM -Confirm:$false Stop-Service ShellHWDetection # Create the fat32 boot partition $usbfat32=(New-Partition -DiskNumber $usb -Size 1GB -AssignDriveLetter -IsActive | Format-Volume -FileSystem FAT32 -NewFileSystemLabel "BOOTFAT").DriveLetter + ":" # Create the ntfs intall partition $usbntfs=(New-Partition -DiskNumber $usb -UseMaximumSize -AssignDriveLetter | Format-Volume -FileSystem NTFS -NewFileSystemLabel "INSTALL").DriveLetter + ":" Start-Service ShellHWDetection # Read-Host "Eject the iso if it is mounted. When ready press Enter" # $Volumes = (Get-Volume).Where({$_.DriveLetter}).DriveLetter # Read-Host "Mount the iso. When ready press Enter" # $ISO = (Compare-Object -ReferenceObject $Volumes -DifferenceObject (Get-Volume).Where({$_.DriveLetter}).DriveLetter).InputObject # $ISO = (get-volume| Where-Object {($_.DriveType -eq "CD-ROM") -and ($_.filesystemlabel -ne "") -and ($_.OperationalStatus -eq "OK")} |Out-GridView -Title 'Select Cd-Rom image' -OutputMode Single).DriveLetter + ":" # $wshell.Popup("Select the iso.",0,"ISO image") | Out-Null # [void]$FileBrowser.ShowDialog() # $ImagePath = $FileBrowser.FileName; $ISO=":" If($FileBrowser.FileNames -like "*\*") { # Check if iso already mounted $ISO = (Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter # Mount iso IF (!$ISO) {Mount-DiskImage -ImagePath $ImagePath -StorageType ISO |out-null $ISO = (Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter} $ISO=$ISO+":" } if ($ISO -eq ":") { # $wshell.Popup("No ISO image mounted or operation cancelled",0,"Error") | Out-Null;exit} ErrorMessage "No ISO image mounted or operation cancelled. Press any key to exit.";exit} # Copy-Item -Path $ISO\* -Destination "$($usbntfs)" -Recurse -Verbose # Copy-Item -Path $ISO"\bootmgr" -Destination $usbfat32"\" -Verbose # Copy-Item -Path $ISO"\bootmgr.efi" -Destination $usbfat32"\" -Verbose # Copy-Item -Path $ISO"\boot" -Destination $usbfat32"\boot" -Recurse -Verbose # Copy-Item -Path $ISO"\efi" -Destination $usbfat32"\efi" -Recurse -Verbose # new-item $usbfat32"\sources" -itemType Directory # Copy-Item -Path $ISO"\sources\boot.wim" -Destination $usbfat32"\sources\boot.wim" -Verbose robocopy $iso $usbntfs /e robocopy $iso"\" $usbfat32"\" bootmgr bootmgr.efi robocopy $iso"\boot" $usbfat32"\boot" /e robocopy $iso"\efi" $usbfat32"\efi" /e robocopy $iso"\sources" $usbfat32"\sources" boot.wim # Eject the mounted iso image # (New-Object -ComObject Shell.Application).Namespace(17).ParseName($ISO).InvokeVerb("Eject") DisMount-DiskImage -ImagePath $ImagePath |out-null Remove-item ($env:TEMP + "\script.ps1")
hello v 1.3 not create boot fat 32 one partition ntfs ? sory no bug resolve problem usb in gpt and rufus ?
New-Partition : A parameter is not valid for this type of partition. Extended information: The parameters MbrType and IsActive cannot be used on a GPT disk. Activity ID: {d17b7f55-1468-47af-b5d0-43b329772c32} Au caractère Ligne:132 : 12 + $usbfat32=(New-Partition -DiskNumber $usb -Size 700MB -AssignDriveLet ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument : (StorageWMI:ROOT/Microsoft/Windows/Storage/MSFT_Disk) [New-Partition], CimException + FullyQualifiedErrorId : StorageWMI 41006,New-Partition New-Partition : A parameter is not valid for this type of partition. Extended information: The parameters MbrType and IsActive cannot be used on a GPT disk. Activity ID: {d17b7f55-1468-47af-b5d0-43b329772c32} Au caractère Ligne:132 : 12 + $usbfat32=(New-Partition -DiskNumber $usb -Size 700MB -AssignDriveLet ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument : (StorageWMI:ROOT/Microsoft/Windows/Storage/MSFT_Disk) [New-Partition], CimException + FullyQualifiedErrorId : StorageWMI 41006,New-Partition
@rpo you think we should add "convert mbr" to the script? Edit: Also in the "ComboBox DropDownList" is it possible to show the USB disk/s instead of partitons? Or the disk/s (with) their partitions? so there's just 1 entry on the list.
@freddie-o "you think we should add "convert mbr" to the script?" : the main purpose of this script is to create a usb stick, so for me short answer : no. But you are free to add the convert. "in the "ComboBox DropDownList" is it possible to show the USB disk/s instead of partitons?" : this makes sense. Just comment or suppress the instructions dealing with partitions . Spoiler Code: Foreach ($USBDisk in $Disks) { $FriendlyName=($USBDisk.FriendlyName).PadRight(30," ").substring(0,30) # $Partitions = Get-Partition | Where-Object { $_.DiskNumber -eq $USBDisk.DiskNumber} # If ($Partitions) { # Foreach ($Partition in $Partitions) { # $Volumes=get-volume | Where-Object {$Partition.AccessPaths -contains $_.path } # Foreach ($Volume in $Volumes) { # $USBDisks+=$USBDisk.DiskNumber # $USBDiskList.Items.Add((" {0,-30}|{1,1}:| {2,-30}| {3:n2} GB" -f $FriendlyName, ($Partition.DriveLetter), $Volume.FileSystemLabel.PadRight(30," ").substring(0,30), ($Partition.Size/1GB)))|out-null # } # } # } Else { $USBDisks+=$USBDisk.DiskNumber $USBDiskList.Items.Add((" {0,-30}| {1,1}| {2,-30}| {3:n2} GB" -f $FriendlyName, " ", " ",($USBDisk.Size/1GB)))|out-null # } }
But if you cannot create a Windows installation disk using a GPT disk, wouldn't "convert mbr" solve the problem? Edit: They would then have to do it manually or use a 3rd party tool.
Hello it is rufus who put me the key usb gpt not mbr his for that I had this error sy it was written in the optional script why not again thank you for your work my problem is solved with a third party tool aomei partition
It seems the solution is easy : ... Clear-Disk $usb -RemoveData -RemoveOEM -Confirm:$false set-disk $usb -partitionstyle mbr Stop-Service ShellHWDetection |out-null ...
v1.4 draft Spoiler Code: <# : standard way of doing hybrid batch + powershell scripts @set "__CMD__=%~f0" &set "__ARGS__=%*" &powershell -noprofile -c "iex([io.file]::ReadAllText(\"%~f0\"))" &exit/b #> # # This script must be executed with admin privilege # # Test Administrator privileges If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(544)) { # Restart the script to get Administrator privileges and exit Start-Process cmd -ArgumentList ("/c call `"$Env:__CMD__`" $Env:__ARGS__") -Verb runAs exit } # We have Administrator privileges # $pswindow = $host.ui.rawui # create a reference to the console’s UI.RawUI child object $pswindow.windowtitle = "Script by: rpo/abbodi1406/BAU/freddie-o [forums.mydigitallife.net]" [console]::ForegroundColor = "yellow" [console]::BackgroundColor = "blue" # Add-Type -AssemblyName System.Windows.Forms # Load the class System.Windows.Forms # Filebrowser dialog $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{ Multiselect = $false # One file can be chosen Filter = 'ISO images (*.iso)|*.iso' # Select iso files } $wshell=New-Object -ComObject Wscript.Shell # clear-host # $Form=New-Object System.Windows.Forms.Form # Create the screen form (window) # Set the title and size of the window: $Form.Text='Windows Installation Disk v1.4' $Form.Width=475 ; $Form.Height=220 $Form.AutoSize=$true # AutoSize property to make the form automatically stretch, if the elements on the form are out of bounds # # Select the USB disk # Create a drop-down list and fill it $USBDiskList=New-Object System.Windows.Forms.ComboBox $USBDiskList.DropDownStyle=[System.Windows.Forms.ComboBoxStyle]::DropDownList; $USBDiskList.Location=New-Object System.Drawing.Point(30,35) $USBDiskList.Width=400;$USBDiskList.height=20 $Form.Controls.Add($SelectUSBDisk) $USB=$Null $USBDisks=@() # array with USB disk number $Disks=Get-Disk | Where-Object {($_.BusType -eq "USB") -and ($_.OperationalStatus -eq "Online")} While (!$Disks) { $Result=$wshell.Popup("Plug in your USB disk first, then click ""OK"", to continue. `r`n`r`nTo close this script, click ""Cancel"".",0,"Plug in the USB disk",1+64) if ($result -eq 2) {Out-Null;exit} $Disks=Get-Disk | Where-Object {($_.BusType -eq "USB") -and ($_.OperationalStatus -eq "Online")} } Foreach ($USBDisk in $Disks) { $FriendlyName=($USBDisk.FriendlyName).PadRight(30," ").substring(0,30) $USBDisks+=$USBDisk.DiskNumber $USBDiskList.Items.Add((" {0,-80} {1,1} {3:n2} GB" -f $FriendlyName, " ", " ",($USBDisk.Size/1GB)))|out-null } $form.Controls.Add($USBDiskList) $USBDiskList.SelectedIndex=0 $SelectUSB=New-Object System.Windows.Forms.Label # Put the SelectUSB label on the form $SelectUSB.Location=New-Object System.Drawing.Size(30,15) $SelectUSB.Text="Select USB disk";$SelectUSB.Font='Default Font,9' $SelectUSB.width=380;$SelectUSB.height=15; $Form.Controls.Add($SelectUSB) $SelectISOButton=New-Object System.Windows.Forms.Button # Put the SelectISO button on the form $SelectISOButton.Location=New-Object System.Drawing.Size(295,135) $SelectISOButton.Text="Select ISO";$SelectISOButton.Font='Default Font,9' $SelectISOButton.Size=New-Object System.Drawing.Size(120,20) $SelectISOButton.width=130;$SelectISOButton.height=25; $Form.Controls.Add($SelectISOButton) $SelectISOButton.DialogResult = [System.Windows.Forms.DialogResult]::OK $CancelButton=New-Object System.Windows.Forms.Button # Put the Cancel button on the form $CancelButton.Location=New-Object System.Drawing.Size(155,135) $CancelButton.Text="Cancel";$CancelButton.Font='Default Font,9' $CancelButton.Size=New-Object System.Drawing.Size(120,20) $CancelButton.width=130;$CancelButton.height=25; $Form.Controls.Add($CancelButton) $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel # $result = $form.ShowDialog() if ($result -eq "Cancel"){$wshell.Popup("The script was cancelled.",0,"Cancel script",0+64) | Out-Null;exit} # $USB=$USBDisks[$USBDiskList.SelectedIndex] # [void]$FileBrowser.ShowDialog() # $ImagePath = $FileBrowser.FileName; if ($ImagePath -eq ""){$wshell.Popup("The script was cancelled.",0,"Cancel script",0+64) | Out-Null;exit} $ISO=":" If($FileBrowser.FileNames -like "*\*") { # Check if iso already mounted $ISO = (Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter # Mount iso IF (!$ISO) {Mount-DiskImage -ImagePath $ImagePath -StorageType ISO |out-null $ISO = (Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter} $ISO=$ISO+":" } if ($ISO -eq ":") {$wshell.Popup("The script was cancelled.",0,"Cancel script",0+64) | Out-Null;exit} # $Result=$wshell.Popup("Warning! Your USB disk will be converted to MBR and reformatted. All data will be lost. `r`n`r`nAre you sure you want to continue? `r`n`r`nTo continue, click ""Yes"". To close this script, click ""No"".",0,"Create Windows installation disk",4+48) if ($result -eq 7) {DisMount-DiskImage -ImagePath $ImagePath |out-null;exit} # Clear the USB stick Clear-Disk $usb -RemoveData -RemoveOEM -Confirm:$false set-disk $usb -partitionstyle mbr Stop-Service ShellHWDetection |out-null # Create the fat32 boot partition $usbfat32=(New-Partition -DiskNumber $usb -Size 700MB -AssignDriveLetter -IsActive | Format-Volume -FileSystem FAT32 -NewFileSystemLabel "BOOT").DriveLetter + ":" # Create the ntfs intall partition $usbntfs=(New-Partition -DiskNumber $usb -UseMaximumSize -AssignDriveLetter | Format-Volume -FileSystem NTFS -NewFileSystemLabel "INSTALL").DriveLetter + ":" Start-Service ShellHWDetection # robocopy $iso $usbntfs /e robocopy $iso"\" $usbfat32"\" bootmgr bootmgr.efi robocopy $iso"\boot" $usbfat32"\boot" /e robocopy $iso"\efi" $usbfat32"\efi" /e robocopy $iso"\sources" $usbfat32"\sources" boot.wim # Eject the mounted iso image DisMount-DiskImage -ImagePath $ImagePath |out-null #done - keep a comment on the last line so the previous useful crlf never gets eaten
@rpo Changed back so the ntfs partition is marked active What do you think about flat buttons...? Spoiler Code: <# : standard way of doing hybrid batch + powershell scripts @set "__CMD__=%~f0" &set "__ARGS__=%*" &powershell -noprofile -c "iex([io.file]::ReadAllText(\"%~f0\"))" &exit/b #> # # This script must be executed with admin privilege # # Test Administrator privileges If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(544)) { # Restart the script to get Administrator privileges and exit Start-Process cmd -ArgumentList ("/c call `"$Env:__CMD__`" $Env:__ARGS__") -Verb runAs exit } # We have Administrator privileges # $pswindow = $host.ui.rawui # create a reference to the console’s UI.RawUI child object $pswindow.windowtitle = "Script by: rpo/abbodi1406/BAU/freddie-o [forums.mydigitallife.net]" [console]::ForegroundColor = "yellow" [console]::BackgroundColor = "blue" # Add-Type -AssemblyName System.Windows.Forms # Load the class System.Windows.Forms # Filebrowser dialog $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{ Multiselect = $false # One file can be chosen Filter = 'ISO images (*.iso)|*.iso' # Select iso files } $wshell=New-Object -ComObject Wscript.Shell # clear-host # $Form=New-Object System.Windows.Forms.Form # Create the screen form (window) # Set the title and size of the window: $Form.Text='Windows Installation Disk v1.4' $Form.Width=475 ; $Form.Height=220 $Form.AutoSize=$true # AutoSize property to make the form automatically stretch, if the elements on the form are out of bounds # # Select the USB disk # Create a drop-down list and fill it $USBDiskList=New-Object System.Windows.Forms.ComboBox $USBDiskList.DropDownStyle=[System.Windows.Forms.ComboBoxStyle]::DropDownList; $USBDiskList.Location=New-Object System.Drawing.Point(30,35) $USBDiskList.Width=400;$USBDiskList.height=20 $Form.Controls.Add($SelectUSBDisk) $USB=$Null $USBDisks=@() # array with USB disk number $Disks=Get-Disk | Where-Object {($_.BusType -eq "USB") -and ($_.OperationalStatus -eq "Online")} While (!$Disks) { $Result=$wshell.Popup("Plug in your USB disk first, then click ""OK"", to continue. `r`n`r`nTo close this script, click ""Cancel"".",0,"Plug in the USB disk",1+64) if ($result -eq 2) {Out-Null;exit} $Disks=Get-Disk | Where-Object {($_.BusType -eq "USB") -and ($_.OperationalStatus -eq "Online")} } Foreach ($USBDisk in $Disks) { $FriendlyName=($USBDisk.FriendlyName).PadRight(30," ").substring(0,30) $USBDisks+=$USBDisk.DiskNumber $USBDiskList.Items.Add((" {0,-80} {1,1} {3:n2} GB" -f $FriendlyName, " ", " ",($USBDisk.Size/1GB)))|out-null } $form.Controls.Add($USBDiskList) $USBDiskList.SelectedIndex=0 $SelectUSB=New-Object System.Windows.Forms.Label # Put the SelectUSB label on the form $SelectUSB.Location=New-Object System.Drawing.Size(30,15) $SelectUSB.Text="Select USB disk";$SelectUSB.Font='Default Font,9' $SelectUSB.width=380;$SelectUSB.height=15; $Form.Controls.Add($SelectUSB) $SelectISOButton=New-Object System.Windows.Forms.Button # Put the SelectISO button on the form $SelectISOButton.Location=New-Object System.Drawing.Size(295,135) $SelectISOButton.Text="Select ISO";$SelectISOButton.Font='Default Font,9' $SelectISOButton.Size=New-Object System.Drawing.Size(120,20) $SelectISOButton.width=130;$SelectISOButton.height=25; $Form.Controls.Add($SelectISOButton) $SelectISOButton.DialogResult = [System.Windows.Forms.DialogResult]::OK $CancelButton=New-Object System.Windows.Forms.Button # Put the Cancel button on the form $CancelButton.Location=New-Object System.Drawing.Size(155,135) $CancelButton.Text="Cancel";$CancelButton.Font='Default Font,9' $CancelButton.Size=New-Object System.Drawing.Size(120,20) $CancelButton.width=130;$CancelButton.height=25; $Form.Controls.Add($CancelButton) $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel # $result = $form.ShowDialog() if ($result -eq "Cancel"){$wshell.Popup("The script was cancelled.",0,"Cancel script",0+64) | Out-Null;exit} # $USB=$USBDisks[$USBDiskList.SelectedIndex] # [void]$FileBrowser.ShowDialog() # $ImagePath = $FileBrowser.FileName; if ($ImagePath -eq ""){$wshell.Popup("The script was cancelled.",0,"Cancel script",0+64) | Out-Null;exit} $ISO=":" If($FileBrowser.FileNames -like "*\*") { # Check if iso already mounted $ISO = (Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter # Mount iso IF (!$ISO) {Mount-DiskImage -ImagePath $ImagePath -StorageType ISO |out-null $ISO = (Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter} $ISO=$ISO+":" } if ($ISO -eq ":") {$wshell.Popup("The script was cancelled.",0,"Cancel script",0+64) | Out-Null;exit} # $Result=$wshell.Popup("Warning! `r`n`r`nYour USB disk will be converted to MBR, repartitioned and reformatted. All data will be lost. `r`n`r`nAre you sure you want to continue? `r`n`r`nTo continue, click ""Yes"". To close this script, click ""No"".",0,"Create the Windows installation disk",4+48) if ($result -eq 7) {DisMount-DiskImage -ImagePath $ImagePath |out-null;exit} # Clear the USB stick Clear-Disk $usb -RemoveData -RemoveOEM -Confirm:$false set-disk $usb -partitionstyle mbr Stop-Service ShellHWDetection |out-null # Create the fat32 boot partition $usbfat32=(New-Partition -DiskNumber $usb -Size 700MB -AssignDriveLetter | Format-Volume -FileSystem FAT32 -NewFileSystemLabel "BOOT").DriveLetter + ":" # Create the ntfs intall partition $usbntfs=(New-Partition -DiskNumber $usb -UseMaximumSize -AssignDriveLetter -IsActive | Format-Volume -FileSystem NTFS -NewFileSystemLabel "INSTALL").DriveLetter + ":" Start-Service ShellHWDetection # robocopy $iso $usbntfs /e robocopy $iso"\" $usbfat32"\" bootmgr bootmgr.efi robocopy $iso"\boot" $usbfat32"\boot" /e robocopy $iso"\efi" $usbfat32"\efi" /e robocopy $iso"\sources" $usbfat32"\sources" boot.wim # Eject the mounted iso image DisMount-DiskImage -ImagePath $ImagePath |out-null #done - keep a comment on the last line so the previous useful crlf never gets eaten