Advertisement
Guest User

Untitled

a guest
May 20th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #This do loop will first run the format script
  2. #Then once it is done it will ask the user if they wish to format another drive
  3. #If the user clicks on "Yes" the process will begin again
  4. #If the user clicks on "No" the loop will end.  Nothing popups on the screen
  5. cls
  6. do {
  7.     $ISOPathforDeploy = "\\share\OS.iso"
  8.     $PartitionType = "FAT32"
  9.     ####################################
  10.     #Please only change variables above.
  11.     #Do not edit code below this line.
  12.     ####################################
  13.     $wshell = New-Object -ComObject Wscript.Shell
  14.     if (-not (Test-Path $ISOPathforDeploy)) { $pathError = $wshell.Popup("ISO path is invalid. Please edit ISOPathforDeploy variable. Ending format.", 0, "Boot Media, 48) }
  15.    else {
  16.        $checkForUSBs = Get-Disk | Where-Object BusType -eq USB
  17.        if (-not $checkForUSBs) { $usbError = $wshell.Popup("No USB detected. Ending format.", 0, "Boot Media", 48) }
  18.        else {
  19.            do {
  20.                $Results = Get-Disk |
  21.                    Where-Object BusType -eq USB |
  22.                    Out-GridView -Title 'Select USB Drive to Format' -OutputMode Single |
  23.                    Clear-Disk -RemoveData -RemoveOEM -Confirm:$false -PassThru |
  24.                    New-Partition -UseMaximumSize -IsActive -AssignDriveLetter |
  25.                    Format-Volume -FileSystem $PartitionType
  26.                $Volumes = (Get-Volume).Where( {$_.DriveLetter}).DriveLetter
  27.                Dismount-DiskImage -ImagePath $ISOPathforDeploy
  28.                Mount-DiskImage -ImagePath $ISOPathforDeploy
  29.                $ISO = (Get-Volume | where {$_.FileSystemLabel -match "Configuration Manager"} | where {$_.SizeRemaining -eq "0"}).DriveLetter
  30.                Set-Location -Path "$($ISO):\boot"
  31.                bootsect.exe /nt60 "$($Results.DriveLetter):"
  32.            }
  33.            until ($results.driveletter -ne $null)
  34.            Copy-Item -Path "$($ISO):\*" -Destination "$($Results.DriveLetter):" -Recurse -Verbose
  35.            Dismount-DiskImage -ImagePath $ISOPathforDeploy
  36.            #End of formatting, asking to re-run script
  37.        }
  38.    }
  39.    $retry = $wshell.Popup("Do you want to format another drive?", 0, "Boot Media", 36)
  40.    if ($retry -eq "6") { $insert = $wshell.Popup("Please insert another flash drive. Press OK when ready to format.", 0, "Boot Media", 64) }
  41.    if ($retry -eq "7") {
  42.        $allDone = $wshell.Popup("Please remove your flash drive.", 0, "Boot Media", 64)
  43.        #exit
  44.    }
  45. }
  46. until ($retry -eq "7")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement