ISOtoUSB - V 2.2.0.2


ISOtoUSB is a simple PowerShell script that burns a ISO file to a drive. The script formats the drive to FAT32 then makes the drive bootable and writes the ISO file to the drive.

Changes to the script since the last version
  • Removed CD/DVD drives from the Available Drives List
  • Add the File System Label to the Available Drives List
  • Added scroll bars to the Available Drives List 
  • Added the ability to name the new volume label 
  • Removed the Cancel button 
  • Removed the window resizing handle 
  • Script now uses Robocopy to write the ISO files to the drive (Better handles the file copy process)
  • reorganized the script to be more inline with my other scripts
You can download ISOtoUSB from the Tools Download Page 






<#

.SYNOPSIS
Script to create a bootable drive from a ISO

.DESCRIPTION
Runs a GUI that will show the available Drives on the computer from there you can choose the drive and ISo file to burn to the drive

.NOTES
Created By: Kris Gross
Contact: KrisGross@sccmtst.com
Twitter: @kmgamd

.LINK
http://sccmtst.com

#>

#Gets the volume info
Function Get-Vol 
{
    Get-Volume | where DriveType -ne "CD-ROM" | Where DriveLetter -ne $Null | Format-Table Driveletter, fileSystemLabel, FileSystem, Drivetype
}

#Generates the form
Function Generate-Form {

    #Needed for the form to show
    Add-Type -AssemblyName System.Windows.Forms
    Add-Type -AssemblyName System.Drawing

    #Set the standrads of the form window
    $form = New-Object System.Windows.Forms.Form 
    $form.Text = "ISOtoUSB - V 2.2.0.2"
    $form.Size = New-Object System.Drawing.Size(460,380) 
    $form.StartPosition = "CenterScreen"
    $Icon = [system.drawing.icon]::ExtractAssociatedIcon(".\ISOtoUSB.exe")
    $Form.Icon = $Icon
    $Form.SizeGripStyle = "Hide"

    #lable for avaliable drives
    $VolumeListLabel = New-Object System.Windows.Forms.Label
    $VolumeListLabel.Location = New-Object System.Drawing.Point(24,20) 
    $VolumeListLabel.Size = New-Object System.Drawing.Size(280,13) 
    $VolumeListLabel.Text = "Avaliable Drives:"

    #Sets the avalibale drives
    $VolumeListBox = New-Object System.Windows.Forms.TextBox
    $VolumeListBox.Location = New-Object System.Drawing.Point(24,40) 
    $VolumeListBox.Size = New-Object System.Drawing.Size(400,100)
    $VolumeListBox.ReadOnly = $True
    $VolumeListBox.Multiline = $True
    $VolumeListBox.Font = 'Lucida Console'
    $VolumeListBox.Text = Get-Vol | Out-String
    $VolumeListBox.MultiLine = $True
    $VolumeListBox.ReadOnly = $True
    $VolumeListBox.Scrollbars = "Both"

    #sets the ok button
    $BurnButton = New-Object System.Windows.Forms.Button
    $BurnButton.Location = New-Object System.Drawing.Point(100,253)
    $BurnButton.Size = New-Object System.Drawing.Size(225,23)
    $BurnButton.Text = "Burn"
    $BurnButton.Add_Click({Run-BurnISO})

    #sets the Browse Button
    $BrowseButton = New-Object System.Windows.Forms.Button
    $BrowseButton.Location = New-Object System.Drawing.Point(320,160)
    $BrowseButton.Size = New-Object System.Drawing.Size(75,23)
    $BrowseButton.Text = "Browse"
    $BrowseButton.Add_Click({Get-FilePath -InitialDirectory "$env:UserProfile\Desktop"})

    #sets the donate button
    $DonateButton = New-Object System.Windows.Forms.Button
    $DonateButton.Location = New-Object System.Drawing.Point(370,1)
    $DonateButton.Size = New-Object System.Drawing.Size(75,20)
    $DonateButton.Text = "Donate"
    $DonateButton.Add_Click({Click_Donate})

    #label for ISO path text box
    $ISOLabel = New-Object System.Windows.Forms.Label
    $ISOLabel.Location = New-Object System.Drawing.Point(24,145)
    $ISOLabel.Size = New-Object System.Drawing.Size(280,13) 
    $ISOLabel.Text = "1. ISO File:"

    #Text box for ISO file location
    $Global:ISOBox = New-Object System.Windows.Forms.TextBox 
    $Global:ISOBox.Location = New-Object System.Drawing.Point(24,165)
    $Global:ISOBox.Size = New-Object System.Drawing.Size(260,22)
    $Global:ISOBox.Font = 'Lucida Console' 
    $Global:ISOBox.Text = ""

    #Label for Drive letter selcetion
    $DriveLetterLabel = New-Object System.Windows.Forms.Label
    $DriveLetterLabel.Location = New-Object System.Drawing.Point(24,190)
    $DriveLetterLabel.Size = New-Object System.Drawing.Size(80,13) 
    $DriveLetterLabel.Text = "2. Drive Letter:"

    #Sets the entry box for Drive letter
    $DriveLetterBox = New-Object System.Windows.Forms.TextBox
    $DriveLetterBox.Location = New-Object System.Drawing.Point(105,190)
    $DriveLetterBox.Size = New-Object System.Drawing.Size(50,22)
    $DriveLetterBox.Font = 'Lucida Console'
    $DriveLetterBox.Text = ""

    $NewVolumeLabel = New-Object System.Windows.Forms.Label
    $NewVolumeLabel.Location = New-Object System.Drawing.Point(24,220)
    $NewVolumeLabel.Size = New-Object System.Drawing.Size(115,13) 
    $NewVolumeLabel.Text = "3. New Volume Label:"

    $NewVolumeBox = New-Object System.Windows.Forms.TextBox
    $NewVolumeBox.Location = New-Object System.Drawing.Point(140,220)
    $NewVolumeBox.Size = New-Object System.Drawing.Size(140,22)
    $NewVolumeBox.Font = 'Lucida Console'
    $NewVolumeBox.Text = ""

    #Create a ProgressBar 
    $ProgressBar = New-Object System.Windows.Forms.ProgressBar
    $ProgressBar.Name = "PowerShellProgressBar"
    $ProgressBar.Size = New-Object System.Drawing.Size(400,20)
    $ProgressBar.Location = New-Object System.Drawing.Point(25,300)
    $ProgressBar.Value = 0
    $ProgressBar.Style="Continuous"

    #label for the progress bar showing what is being copied
    $ProgressBarLabel = New-Object System.Windows.Forms.Label
    $ProgressBarLabel.Location = New-Object System.Drawing.Point(25,280)
    $ProgressBarLabel.Size = New-Object System.Drawing.Size(280,13)
    $ProgressBarLabel.Text = ""

    #Add all resorces of the form 
    $form.Controls.Add($BurnButton)
    $form.Controls.Add($BrowseButton)
    $form.Controls.Add($objDrives)
    $form.Controls.Add($Global:ISOBox)
    $form.Controls.Add($DriveLetterLabel) 
    $form.Controls.Add($ISOLabel) 
    $form.Controls.Add($VolumeListBox)
    $form.Controls.Add($DriveLetterBox)
    $form.Controls.Add($VolumeListLabel)
    $form.Controls.Add($ProgressBarLabel)
    $form.Controls.Add($ProgressBar)
    $form.Controls.Add($DonateButton)
    $form.Controls.Add($NewVolumeLabel)
    $form.Controls.Add($NewVolumeBox)

    #Show the Form 
    $form.Topmost = $True
    [void]$form.ShowDialog()
}

#Opend the file broswser to select your ISO File
Function Get-FilePath{
[CmdletBinding()]
Param(
    [String]$Filter = "|*.ISO",
    [String]$InitialDirectory = "C:\")
    [void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
    $OpenFileDialog.initialDirectory = $InitialDirectory
    $OpenFileDialog.filter = $Filter
    [void]$OpenFileDialog.ShowDialog()
    $OpenFileDialog.filename
    $Global:ISOFile = $OpenFileDialog.filename
    $Global:ISOBox.Text = $Global:ISOFile
    #Runs the form function over so the results are added to the text box
}

#Runs the Burn process
Function Run-BurnISO 
{
    $ProgressBarLabel.text = "Preparing Drive. Please wait..."
    #Sets ISO file and disk letter
    $iso = $Global:ISOBox.Text
    $disk = $DriveLetterBox.Text
    #Gets the disk number for diskpart
    $DriveNumber = (Get-Partition -DriveLetter $disk).DiskNumber
    #Mounts the ISO file
    Mount-DiskImage -ImagePath "$iso"
    $FSLabel = $NewVolumeBox.Text
    Format-Volume -DriveLetter $disk -FileSystem FAT32 -NewFileSystemLabel "$FSLabel" -Force

    #gets the drive letter of where the ISO gets mounted to
    $MountLetter = (Get-DiskImage $iso | Get-Volume).DriveLetter

    #Sets Variable for copy process
    $Source = $MountLetter + ":\"
    $Destination = $disk + ":\"
    $bootdir = $disk + ":"

    #Makes the drive bootbale
    bootsect.exe /nt60 $bootdir

    if ($Source -notlike $null) {
    $sourcefiles = robocopy.exe $Source $Destination /L /E /NJH /BYTES /FP /NC /TS /XJ /R:0 /W:0
    # If ($sourcefiles[-5] -match '^\s{3}Files\s:\s+(?<Count>\d+).*') {$filecount=$matches.Count}
    $filecount = $sourcefiles.Count
    }
    $ProgressBarLabel.Text = "Burning"
    robocopy.exe $Source $Destination /E /J /R:0 /W:0 | foreach {
    $ErrorActionPreference = "silentlycontinue"
    #calculate percentage
    $i++
    [int]$pct = ($i/$filecount)*100
    #update the progress bar
    $progressbar.Value = ($pct)
    $ProgressBarLabel.text = ($_ + "`r")
    [void] [System.Windows.Forms.Application]::DoEvents()
    }
 
    #Dismounts the ISO file
    Dismount-DiskImage -ImagePath "$iso"
    $ProgressBarLabel.forecolor = "Green"
    $ProgressBarLabel.text = "Complete"
}

Function Click_Donate
{
    [System.Diagnostics.Process]::Start("https://www.paypal.me/jackofalltech")
}

#Call the Function 
Generate-Form

Popular posts from this blog

SCCM Task Sequence GUI - How to set up the TS to work with a GUI

SCCM Applications vs. SCCM Packages: Understanding the Key Differences

How to Deploy a Windows 10 Servicing update as a Application