ISOtoUSB


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

Change Log

3-28-18
  • Fixed a issue that would stop the ISO file from being dismounted if the file path had a space
  • Fixed a issue that caused the progress description to be obscured by the burn button 
  • Added error logging to the GUI progress description

1-31-18
  • Added NTFS and FAT32 file system support 
  • Recompiled to exe to a better format 
  • Updated the icon file to be in the script 
8-2-17
  • 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 and other tools from the Tools Download Page

Download ISOtoUSB






I have removed the text code for the image file to help keep the script smaller


<#
.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
Version 2.3.2.5

.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.3.2.5"
    $form.Size = New-Object System.Drawing.Size(460,380) 
    $form.StartPosition = "CenterScreen"
    $Icon = [System.IO.MemoryStream][System.Convert]::FromBase64String($Image)
    $Form.Icon = $Icon
    $Form.SizeGripStyle = "Hide"
    $Form.MinimizeBox = $False
    $Form.MaximizeBox = $False

    #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.Font = 'Lucida Console'
    $VolumeListBox.Text = Get-Vol | Out-String
    $VolumeListBox.MultiLine = $True
    $VolumeListBox.ReadOnly = $True
    $VolumeListBox.Scrollbars = "Both"

    #Powershell check box 
    $NTFSCheckBox = New-Object System.Windows.Forms.Checkbox
    $NTFSCheckBox.Name = "NTFS"
    $NTFSCheckBox.Location = New-Object System.Drawing.Point(25,250)
    $NTFSCheckBox.Size = New-object System.Drawing.Size(145,30)
    $NTFSCheckBox.Text = "NTFS"
    $NTFSCheckBox.Checked = $False
    $NTFSCheckBox.add_MouseHover($ShowHelp)
    $NTFSCheckBox.Add_CheckStateChanged({IF($NTFSCheckBox.Checked) 
        {
            $FAT32CheckBox.Checked = $false
        }})

    #Powershell check box 
    $FAT32CheckBox = New-Object System.Windows.Forms.Checkbox
    $FAT32CheckBox.Name = "FAT32"
    $FAT32CheckBox.Location = New-Object System.Drawing.Point(200,250)
    $FAT32CheckBox.Size = New-object System.Drawing.Size(145,30)
    $FAT32CheckBox.Text = "FAT32"
    $FAT32CheckBox.Checked = $True
    $FAT32CheckBox.add_MouseHover($ShowHelp)
    $FAT32CheckBox.Add_CheckStateChanged({IF($FAT32CheckBox.Checked) 
        {
            $NTFSCheckBox.Checked = $False
        }})


    #sets the ok button
    $BurnButton = New-Object System.Windows.Forms.Button
    $BurnButton.Location = New-Object System.Drawing.Point(100,285)
    $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:"

    $DriveLetterSelect = New-Object System.Windows.Forms.ComboBox
    $DriveLetterSelect.Location = New-Object System.Drawing.Point(105,190)
    $DriveLetterSelect.Size = New-Object System.Drawing.Size(50,22)
    $DriveLetterSelect.DropDownStyle = "DropDownList"
    Foreach ($item in ((Get-Volume | where DriveType -ne "CD-ROM" | Where DriveLetter -ne $Null).DriveLetter))
    {
     $DriveLetterSelect.Items.Add($item) | Out-Null
    }

    $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 = ""

    #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,315)
    $ProgressBarLabel.Size = New-Object System.Drawing.Size(400,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($DriveLetterSelect)
    $form.Controls.Add($VolumeListLabel)
    $form.Controls.Add($ProgressBarLabel)
    $form.Controls.Add($DonateButton)
    $form.Controls.Add($NewVolumeLabel)
    $form.Controls.Add($NewVolumeBox)
    $form.Controls.Add($NTFSCheckBox)
    $form.Controls.Add($FAT32CheckBox)

    #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 = $DriveLetterSelect.Text
    #Mounts the ISO file
    $ProgressBarLabel.text = "Mounting ISO"
    Mount-DiskImage -ImagePath "$iso"
    $VolumeLabel = $NewVolumeBox.Text

    IF ($NTFSCheckBox.Checked)
    {
        $FS = "ntfs"
    }
    IF ($FAT32CheckBox.Checked)
    {
        $FS = "fat32"
    }

    $Destination = $disk + ":\"
    IF (!(Test-Path $Destination))
    {
        $Er = 1
        $ProgressBarLabel.ForeColor = "Red"
        $ProgressBarLabel.Text = "ERROR: Could not find $Destination"
    }

    If ($Er -NE 1)
    {
        $ProgressBarLabel.Text = "Formating $disk"
        Try{
            Format-Volume -DriveLetter $disk -FileSystem $FS -NewFileSystemLabel "$VolumeLabel" -Force -InformationAction SilentlyContinue -ErrorAction Stop | Out-Null
        }
        Catch
        {
            $Er = 1
            $ProgressBarLabel.ForeColor = "Red"
            $ProgressBarLabel.Text = "$_"
        }
    }

    #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 + ":\"
    $bootdir = $disk + ":"

    IF ($Er -ne 1)
    {
        #Makes the drive bootbale
        $ProgressBarLabel.Text = "Making $disk bootable"
        bootsect.exe /nt60 $bootdir
        If ($LASTEXITCODE -eq 1)
        {
            $Er = 1
            $ProgressBarLabel.ForeColor = "Red"
            $ProgressBarLabel.Text = "ERROR: Could not update boot code" 
        }
    }
    
    If ($Er -ne 1)
    {
        $ProgressBarLabel.text = "Burning ISO to $disk"
$CopyScript = 
@"
@ECHO off
cls
title ISOtoUSB
color 0A
cls
robocopy.exe $Source $Destination /E /J /R:0 /W:0
powershell.exe -NOPROFILE -command "Dismount-DiskImage -ImagePath '$iso'"
exit cmd.exe
"@

        Add-Content $Env:TEMP\ISOtoUSB.bat $CopyScript
        invoke-expression "cmd /c start $ENV:TEMP\ISOtoUSB.bat"
        remove-item $Env:TEMP\ISOtoUSB.bat
        $ProgressBarLabel.forecolor = "Green"
        $ProgressBarLabel.text = "Complete"
    }
    
    Dismount-DiskImage -ImagePath "$iso" | Out-Null
}

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

#Call the Function 
Generate-Form

Comments

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