Private/Write-ToUsb.ps1

function Write-ToUsb {
    [CmdletBinding()]
    param (
        [Parameter()]
        [ImageUSBClass]
        $usbImage
    )
    $unzipSourcePath = Join-Path $usbImage.downloadPath -childpath  $usbImage.localPath
    $unzipDestPath = $unzipSourcePath -replace '.zip', ""
    Write-Verbose $usbImage.downloadPath
    Write-Verbose $usbImage.localPath
    Write-Verbose $unzipSourcePath
    Write-Verbose $unzipDestPath
    if ( $usbImage.DirCount -eq 1 ) {
        $folders = (Get-ChildItem $unzipDestPath)
        foreach ($folder in $folders) {
            $folderName = $folder.name
        }
        $copySource = Join-Path -path $unzipDestPath -childpath $folderName
        $copySource = Join-Path -path $copySource -ChildPath "*"
        #copy main image files
        Copy-Item $copySource -Destination "$($usbImage.drive):\" -Recurse -Verbose
        #Create lnaguage path
        New-Item -ItemType Directory -Force -Path "$($usbImage.drive):\ImagePostInstallPatch\CopyToDisk\"
    }
    elseif ( $usbImage.DirCount -eq 2  ) {
        $folders = (Get-ChildItem $unzipDestPath)
        foreach ($folder in $folders) {
            $folderName = $folder.name
            if ($folderName -eq $usbImage.dirName) {
                $copySource = Join-Path -path $unzipDestPath -childpath $folderName
                $copySource = Join-Path -path $copySource -ChildPath "*"
            }
            elseif ($folderName -eq $usbImage.dirName2) {
                $copySource2 = Join-Path -path $unzipDestPath -childpath $folderName
            }
        }
        #copy main image files
        Write-Verbose "USB Source: $copySource"
        #Copy-Item $copySource -Destination "$($usbImage.drive):\" -Recurse
        $progressDiag = "&H0&"
        $yesToAll = "&H16&"
        $simpleProgress = "&H100&"
        $opts = $progressDiag + $yesToAll + $simpleProgress
        $objShell = New-Object -ComObject "Shell.Application"
        $objFolder = $objShell.NameSpace("$($usbImage.drive):\")
        $objFolder.CopyHere($copySource, $opts)
        #Create lnaguage path
        #copy second image files
        Write-Verbose "USB Source2: $copySource2"
        #Copy-Item "$copySource2\Images" -Destination "$($usbImage.drive2):\" -Recurse
        $objShell = New-Object -ComObject "Shell.Application"
        $objFolder = $objShell.NameSpace("$($usbImage.drive2):\")
        $objFolder.CopyHere("$copySource2\Images", $opts)
    }
}