Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This do loop will first run the format script
- #Then once it is done it will ask the user if they wish to format another drive
- #If the user clicks on "Yes" the process will begin again
- #If the user clicks on "No" the loop will end. Nothing popups on the screen
- cls
- do {
- $ISOPathforDeploy = "\\share\OS.iso"
- $PartitionType = "FAT32"
- ####################################
- #Please only change variables above.
- #Do not edit code below this line.
- ####################################
- $wshell = New-Object -ComObject Wscript.Shell
- if (-not (Test-Path $ISOPathforDeploy)) { $pathError = $wshell.Popup("ISO path is invalid. Please edit ISOPathforDeploy variable. Ending format.", 0, "Boot Media, 48) }
- else {
- $checkForUSBs = Get-Disk | Where-Object BusType -eq USB
- if (-not $checkForUSBs) { $usbError = $wshell.Popup("No USB detected. Ending format.", 0, "Boot Media", 48) }
- else {
- do {
- $Results = Get-Disk |
- Where-Object BusType -eq USB |
- Out-GridView -Title 'Select USB Drive to Format' -OutputMode Single |
- Clear-Disk -RemoveData -RemoveOEM -Confirm:$false -PassThru |
- New-Partition -UseMaximumSize -IsActive -AssignDriveLetter |
- Format-Volume -FileSystem $PartitionType
- $Volumes = (Get-Volume).Where( {$_.DriveLetter}).DriveLetter
- Dismount-DiskImage -ImagePath $ISOPathforDeploy
- Mount-DiskImage -ImagePath $ISOPathforDeploy
- $ISO = (Get-Volume | where {$_.FileSystemLabel -match "Configuration Manager"} | where {$_.SizeRemaining -eq "0"}).DriveLetter
- Set-Location -Path "$($ISO):\boot"
- bootsect.exe /nt60 "$($Results.DriveLetter):"
- }
- until ($results.driveletter -ne $null)
- Copy-Item -Path "$($ISO):\*" -Destination "$($Results.DriveLetter):" -Recurse -Verbose
- Dismount-DiskImage -ImagePath $ISOPathforDeploy
- #End of formatting, asking to re-run script
- }
- }
- $retry = $wshell.Popup("Do you want to format another drive?", 0, "Boot Media", 36)
- if ($retry -eq "6") { $insert = $wshell.Popup("Please insert another flash drive. Press OK when ready to format.", 0, "Boot Media", 64) }
- if ($retry -eq "7") {
- $allDone = $wshell.Popup("Please remove your flash drive.", 0, "Boot Media", 64)
- #exit
- }
- }
- until ($retry -eq "7")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement