Advertisement
LaDEEKill3R

Win10 Setup Disk 2.4 Re-Upload by ITGroceries

Sep 25th, 2021
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 9.77 KB | None | 0 0
  1. <# : standard way of doing hybrid batch + powershell scripts
  2. @title Win10 Setup Disk 2.4 &color f0
  3. @set "__ARGS__=%*" &powershell -noprofile "$ScriptPath='%~f0';iex((Get-Content('%~f0') -Raw))" &exit/b
  4. #>
  5. #
  6. #   Homepage: https://forums.mydigitallife.net/threads/win10-setup-disk-works-with-uefi-with-secure-boot-bios-install-wim-over-4-gb.79268/
  7. #   Credits: @rpo, @freddie-o, @BAU & @abbodi1406
  8. #
  9. #   This script must be executed with admin privilege
  10. #
  11. #   Test Administrator privileges
  12. If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
  13. {
  14.     $uac_error="Elevating UAC for Administrator Privileges failed"
  15.     #   The following test is to avoid infinite looping if elevating UAC for Administrator Privileges failed
  16.     if ($env:__ARGS__ -eq $uac_error) {
  17.     read-host "$uac_error`r`nRight click on the script and select ""Run as administrator""`r`nPress Enter to exit...";exit}
  18. #   Restart the script to get Administrator privileges and exit
  19.                                                                                        
  20.     Start-Process "$ScriptPath" $uac_error -Verb runAs; exit
  21. }
  22. $pswindow = $host.ui.rawui          # create a reference to the console’s UI.RawUI child object
  23. $pswindow.windowtitle = ([string]($pswindow.windowtitle -split "^.*  ")).trim() ; $ShortTitle=($pswindow.windowtitle -split " @ .*")[0]
  24. #
  25. Add-Type -AssemblyName System.Windows.Forms # Load the class System.Windows.Forms
  26. #
  27. # Filebrowser dialog object
  28. $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
  29.     Multiselect = $false # One file can be chosen
  30.     Filter = 'ISO images (*.iso)|*.iso' # Select only iso files
  31. }
  32. #
  33. Function MsgBox {[System.Windows.Forms.MessageBox]::Show($Args[0],$ShortTitle,$Args[1],$Args[2])}
  34. #
  35. clear-host
  36. $USB=$Null
  37. $Form=New-Object System.Windows.Forms.Form # Create the screen form (window)
  38. $Form.TopMost = $True
  39. # Set the title and size of the window:
  40. $Form.Text=$ShortTitle
  41. $Form.Font='Consolas,10'
  42. $Form.Width=420 ; $Form.Height=265
  43. $Form.StartPosition = "CenterScreen"
  44. $Form.SizeGripStyle = "Hide"
  45. [System.Windows.Forms.Application]::EnableVisualStyles();
  46.  
  47. # Create a drop-down list and fill it
  48. $USBDiskList=New-Object System.Windows.Forms.ComboBox
  49. $USBDiskList.DropDownStyle=[System.Windows.Forms.ComboBoxStyle]::DropDownList;
  50. $USBDiskList.Location=New-Object System.Drawing.Point(20,50)
  51. $USBDiskList.Size=New-Object System.Drawing.Size(363,22)
  52.  
  53. $Form.Controls.Add($SelectUSBDiskList)
  54. $USBDisks=@() # array with USB disk number
  55. #
  56. $Disks=$Null;While (!$Disks){
  57.     If(!($Disks=Get-Disk | Where-Object {($_.BusType -eq "USB") -and ($_.OperationalStatus -eq "Online")})){
  58.         if((MsgBox "Please plug in your USB disk first. `n`nClick OK to continue." "OKCancel" "Information") -eq "Cancel") {exit}}}
  59.  
  60. $USBDisk=New-Object System.Windows.Forms.Label # Put the USB Disk label on the form
  61. $USBDisk.Location=New-Object System.Drawing.Point(20,30)
  62. $USBDisk.Text="USB Disk"                     
  63. $USBDisk.Size=New-Object System.Drawing.Size(200,20)
  64. $Form.Controls.Add($USBDisk)
  65.  
  66. $ISOImage=New-Object System.Windows.Forms.Label # Put the ISO Image label on the form
  67. $ISOImage.Location=New-Object System.Drawing.Point(20,95)                  
  68. $ISOImage.Size=New-Object System.Drawing.Size(200,20)
  69. $ISOImage.text="ISO Image"
  70. $Form.Controls.Add($ISOImage)
  71.  
  72. $ISOFile=New-Object System.Windows.Forms.Label # Put the ISO file name on the form
  73. $ISOFile.Location=New-Object System.Drawing.Point(20,115)
  74. $ISOFile.Text=" "
  75. $ISOFile.Size=New-Object System.Drawing.Size(364,24)
  76. $ISOFile.Backcolor = [System.Drawing.Color]::White
  77. $ISOFile.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
  78. $Form.Controls.Add($ISOFile)
  79.  
  80. $CancelButton=New-Object System.Windows.Forms.Button # Put the Cancel button on the form
  81. $CancelButton.Location=New-Object System.Drawing.Point(285,180)
  82. $CancelButton.Text="Cancel"                        
  83. $CancelButton.Size=New-Object System.Drawing.Size(100,26)
  84. $Form.Controls.Add($CancelButton)
  85. $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
  86.  
  87. $SelectISOButton=New-Object System.Windows.Forms.Button # Put the Select ISO button on the form
  88. $SelectISOButton.Location=New-Object System.Drawing.Point(175,180)
  89. $SelectISOButton.Text="Select ISO"                           
  90. $SelectISOButton.Size=New-Object System.Drawing.Size(100,26)
  91. $Form.Controls.Add($SelectISOButton)
  92.  
  93. $CreateDiskButton=New-Object System.Windows.Forms.Button # Put the Create Disk button on the form
  94. $CreateDiskButton.Location=New-Object System.Drawing.Point(65,180)
  95. $CreateDiskButton.Text="Create Disk"                                   
  96. $CreateDiskButton.Size=New-Object System.Drawing.Size(100,26)
  97. $Form.Controls.Add($CreateDiskButton)
  98. $CreateDiskButton.Enabled = $false
  99. $CreateDiskButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
  100.  
  101. $SelectISOButton.Add_Click({
  102.     If ($FileBrowser.ShowDialog() -ne "Cancel"){ # if Cancel, just ignore
  103.         $Global:ImagePath = $FileBrowser.filename    # return the file name
  104.         $ISOFile.Text= Split-Path -Path $ImagePath -leaf # extract filename and extension (iso)
  105.         if (($ISOFile.Text).length -gt 44) {$ISOFile.Text = $ImagePath.PadRight(100," ").substring(0,43)+"..."}
  106.         $CreateDiskButton.Enabled = $true
  107.         $CreateDiskButton.Focus()}})
  108.  
  109. Foreach ($USBDisk in $Disks) {
  110.     $FriendlyName=($USBDisk.FriendlyName).PadRight(40," ").substring(0,39)
  111.     $USBDisks+=$USBDisk.DiskNumber
  112.     $USBDiskList.Items.Add(("{0,-39}{1:n2} GB" -f $FriendlyName,($USBDisk.Size/1GB)))|out-null
  113.     $Partitions = Get-Partition | Where-Object { $_.DiskNumber -eq $USBDisk.DiskNumber}
  114.     If ($Partitions) {
  115.         Foreach ($Partition in $Partitions) {
  116.         If(!$Partition.DriveLetter){$AccessPath="  "} Else {$AccessPath=$Partition.DriveLetter+":"}    
  117.         $Volumes=get-volume | Where-Object {$Partition.AccessPaths -contains  $_.path }
  118.             Foreach ($Volume in $Volumes) {
  119.                 $USBDisks+=$USBDisk.DiskNumber
  120.                 $USBDiskList.Items.Add(("{0,0}({1,2}){2,-32}[{3:n2} GB]" -f " ", ($AccessPath), $Volume.FileSystemLabel.PadRight(25," ").substring(0,25), ($Partition.Size/1GB)))|out-null
  121.             }
  122.         }
  123.     }
  124. }
  125. $form.Controls.Add($USBDiskList)
  126. $USBDiskList.SelectedIndex=0
  127. #
  128. $Groupbox=New-Object System.Windows.Forms.Groupbox # Add a group box on the form
  129. $Groupbox.Location=New-Object System.Drawing.Point(7,0)
  130. $Groupbox.Text=""
  131. $Groupbox.Size=New-Object System.Drawing.Size(390,220)
  132. $Form.Controls.Add($Groupbox)
  133. #
  134. if($form.ShowDialog() -eq "Cancel") {MsgBox "The script was cancelled." "OK" "Information"|out-Null;exit}
  135. #
  136. # At this point the mounted USB disk and the iso image file path are defined
  137. #
  138. $USB=$USBDisks[$USBDiskList.SelectedIndex]
  139. #
  140. If((MsgBox "WARNING! `n`nYour USB disk will be converted to MBR scheme, repartitioned and reformatted.`n`nAll partitions and data currently stored in the USB disk will be erased.`r`n`r`nAre you sure you want to continue?" "YESNO" "Warning") -eq "NO"){exit}
  141. # Mount the image file if not already mounted and get the drive letter
  142. #
  143. #   Check if iso already mounted by getting driveletter
  144. If($ISO=(Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter){$Mounted=$True}    Else
  145. #    Mount iso and get drive letter
  146.     {$Mounted=$False; Mount-DiskImage -ImagePath $ImagePath -StorageType ISO |out-null
  147.      If(!($ISO=(Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter)){Exit}}
  148. $ISO=$ISO+":"    
  149. # set bootmenupolicy Legacy
  150. Copy-Item $ISO"\boot\bcd" $env:temp\bcdmbr -Force
  151. & bcdedit /store ($env:temp + "\bcdmbr") /set '{default}' bootmenupolicy Legacy
  152. Set-ItemProperty -Path ($env:temp + "\bcdmbr") -Name IsReadOnly -Value $true
  153. Copy-Item $ISO"\EFI\Microsoft\boot\bcd" $env:temp\bcdefi -Force
  154. & bcdedit /store ($env:temp + "\bcdefi") /set '{default}' bootmenupolicy Legacy
  155. Set-ItemProperty -Path ($env:temp + "\bcdefi") -Name IsReadOnly -Value $true
  156. #
  157. Clear-Host
  158. #    Clear the USB disk
  159. @"
  160. Select disk $USB
  161. clean
  162. convert MBR
  163. rescan
  164. exit
  165. "@ | diskpart
  166. Stop-Service ShellHWDetection -erroraction silentlycontinue|out-null
  167. #   Create the fat32 boot partition
  168. $usbfat32=(New-Partition -DiskNumber $usb -Size  1GB -AssignDriveLetter | Format-Volume -FileSystem FAT32 -NewFileSystemLabel "BOOT").DriveLetter + ":"
  169. #   Copy needed files to the fat32 boot partition
  170. robocopy $iso"\" $usbfat32"\" bootmgr bootmgr.efi
  171. robocopy $iso"\boot" $usbfat32"\boot" /e /xf $iso\boot\bcd
  172. robocopy $iso"\efi" $usbfat32"\efi" /e /xf $iso\efi\microsoft\boot\bcd
  173. robocopy $iso"\sources" $usbfat32"\sources" boot.wim
  174. Copy-Item ($env:temp + "\bcdmbr") $usbfat32"\boot\bcd" -Force
  175. Copy-Item ($env:temp + "\bcdefi") $usbfat32"\EFI\Microsoft\boot\bcd" -Force
  176. #   Remove the drive letter to hide the device
  177. Get-Volume -DriveLetter $usbfat32.substring(0,$usbfat32.Length-1) | Get-Partition | Remove-PartitionAccessPath -accesspath $usbfat32
  178. #
  179. #    Create the NTFS intall partition
  180. $usbntfs=(New-Partition -DiskNumber $usb -UseMaximumSize -AssignDriveLetter -IsActive | Format-Volume -FileSystem NTFS -NewFileSystemLabel "SETUP").DriveLetter + ":"
  181. Start-Service ShellHWDetection -erroraction silentlycontinue|out-null
  182. #
  183. #   Copy needed files to the NTFS install partition
  184. robocopy $iso $usbntfs /e /xf $iso\boot\bcd $iso\efi\microsoft\boot\bcd
  185. Copy-Item ($env:temp + "\bcdmbr") $usbntfs"\boot\bcd" -Force
  186. Copy-Item ($env:temp + "\bcdefi") $usbntfs"\EFI\Microsoft\boot\bcd" -Force
  187. #
  188. #   House keeping
  189. remove-item ($env:temp + "\bcdmbr") -force
  190. remove-item ($env:temp + "\bcdmbr.*") -force
  191. remove-item ($env:temp + "\bcdefi") -force
  192. remove-item ($env:temp + "\bcdefi.*") -force
  193. #
  194. # Eject the mounted iso image if it was loaded by the script
  195. If(!$Mounted){DisMount-DiskImage -ImagePath $ImagePath |out-null}
  196. MsgBox (($ShortTitle -split " @.*")[0]+" was created successfully.") "OK" "Information" |Out-Null;exit
  197.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement