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
Brought improvement (?) to the combobox : Code: Foreach ($USBDisk in $Disks) { $FriendlyName=($USBDisk.FriendlyName).PadRight(36," ").substring(0,36) $USBDisks+=$USBDisk.DiskNumber $USBDiskList.Items.Add(("{0,-36}|{1:n2} GB" -f $FriendlyName,($USBDisk.Size/1GB)))|out-null $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,-7}|{1,1}:|{2,-3}|{3:n2} GB" -f " ", ($Partition.DriveLetter), $Volume.FileSystemLabel.PadRight(25," ").substring(0,25), ($Partition.Size/1GB)))|out-null } } } } The disk name is displayed, followed by partition informations if present. User can select disk or partition. A non-proportional font should be used for displaying. I use Courier New.
You can get the disk number by executing diskpart and entering list disk. IMHO it's not usefull to display this information.
Modified how the partitions are displayed in the combobox a bit Code: Foreach ($USBDisk in $Disks) { $FriendlyName=($USBDisk.FriendlyName).PadRight(36," ").substring(0,36) $USBDisks+=$USBDisk.DiskNumber $USBDiskList.Items.Add(("{0,-80}{1:n2} GB" -f $FriendlyName,($USBDisk.Size/1GB)))|out-null $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,-1}{1,1}:{2,-60}{3:n2} GB )" -f " ", ($Partition.DriveLetter), $Volume.FileSystemLabel.PadRight(25," ").substring(0,25), ($Partition.Size/1GB)))|out-null } } } }
This does not work properly for me... It creates the BOOT 700MB FAT32 partition on an 8GB USB Drive, closes the CMD window and QUITS... No NTFS partition is created therefore, the .iso files are not copied to the USB Drive... The remaining unused portion of the USB Drive is a 6.78 GB Unallocated partition... I ran CMD as Admin... The .iso is a LTSC 2019 w/ CU .678 created with W10UI_6.6 and is located in a folder on Desktop with the Windows Installation Disk v1.4.cmd
Sorry MMIKEE, something else in your system, might be interfering with the script. I tested it on 2 different OSes with no problems.
Added a pop up after the script finishes. 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(36," ").substring(0,36) $USBDisks+=$USBDisk.DiskNumber $USBDiskList.Items.Add(("{0,-80}{1:n2} GB" -f $FriendlyName,($USBDisk.Size/1GB)))|out-null $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,-1}{1,1}:{2,-60}{3:n2} GB )" -f " ", ($Partition.DriveLetter), $Volume.FileSystemLabel.PadRight(25," ").substring(0,25), ($Partition.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 the MBR scheme. It will be 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 $wshell.Popup("The Windows Installation Disk is complete.",0,"Complete",0+64) | Out-Null;exit #done - keep a comment on the last line so the previous useful crlf never gets eaten
As i told you before (cf post #141), a non-proportional font should be used for displaying. I use Courier New. This is what i coded: Spoiler Code: ... $USBDiskList.Width=380;$USBDiskList.height=20;$USBDiskList.Font='Courier New,10' ... Foreach ($USBDisk in $Disks) { $FriendlyName=($USBDisk.FriendlyName).PadRight(36," ").substring(0,36) $USBDisks+=$USBDisk.DiskNumber $USBDiskList.Items.Add(("{0,-36}|{1:n2} GB" -f $FriendlyName,($USBDisk.Size/1GB)))|out-null $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,-7}({1,1}:){2,-3}|{3:n2} GB" -f " ", ($Partition.DriveLetter), $Volume.FileSystemLabel.PadRight(25," ").substring(0,25), ($Partition.Size/1GB)))|out-null } } } } .... Some adjustements have to be made.
Use only fixed fonts for the combobox. Proportional fonts are ok for the other texts. Change $SelectUSB.Text to "Select USB disk or partition" : click on disk or partition have the same effect; only the disk number is used. A timeout of 2 seconds is added for the popup cancel messages; after that the popup closes. 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;$USBDiskList.Font='Lucida sans Typewriter,10' $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(36," ").substring(0,36) $USBDisks+=$USBDisk.DiskNumber $USBDiskList.Items.Add(("{0,-40}{1:n2} GB" -f $FriendlyName,($USBDisk.Size/1GB)))|out-null $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,-3}({1,1}:){2,-33}{3:n2} GB" -f " ", ($Partition.DriveLetter), $Volume.FileSystemLabel.PadRight(25," ").substring(0,25), ($Partition.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 or partition";$SelectUSB.Font='Consolas,10' $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(300,135) $SelectISOButton.Text="Select ISO";$SelectISOButton.Font='Consolas,10' $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(160,135) $CancelButton.Text="Cancel";$CancelButton.Font='Consolas,10' $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 # if ($form.ShowDialog() -eq "Cancel"){$wshell.Popup("The script was cancelled.",2,"Cancel script",0+64) | Out-Null;exit} # $USB=$USBDisks[$USBDiskList.SelectedIndex] # if ($FileBrowser.ShowDialog() -eq "Cancel"){$wshell.Popup("The script was cancelled.",2,"Cancel script",0+64) | Out-Null;exit} # $ImagePath = $FileBrowser.FileName; if ($ImagePath -eq ""){$wshell.Popup("The script was cancelled.",2,"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.",2,"Cancel script",0+64) | Out-Null;exit} # $Result=$wshell.Popup("Warning! Your USB disk will be converted to MBR scheme, 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;$wshell.Popup("The script was cancelled.",2,"Cancel script",0+64) | 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 $wshell.Popup("The Windows Installation Disk is complete.",0,"Complete",0+64) | Out-Null;exit #done - keep a comment on the last line so the previous useful crlf never gets eaten
Are there consequences to using proportional fonts for the drop box? The partition/s listed in the drop box are supposedly for information only. Better to just Select USB disk so less confusion.
When you look at the picture on the left of post #149, you can see that it is not neat; that is the only drawback with proportional fonts. It's only "cosmetic". If you prefer proportional fonts, it's up to you.