LogoLogo
OSDeploy.comTwitterGitHubPowerShell Gallery
  • OSD PowerShell Module
  • Functions
  • Docs
    • OSDCloud
    • OSDPad
    • OSDHelp
      • Autopilot
    • Guides
      • UEFI System Firmware Update
      • In Your Code
      • New-OSDBoot.usb
      • Partitions
        • New-OSDDisk (Information)
        • New-OSDDiskWinPE (GPT)
        • New-OSDDiskWinPE (2 Disks)
        • AutoUnattend.xml
    • OSDWindowsImage
    • Windows Setup Environment
      • Execution Policy
      • WinSE Settings
      • Import Modules
      • Automation
    • Release Notes
    • Trash
      • Adk
        • Edit-ADKwinpe.wim
        • Get-ADKpaths
        • New-ADK.iso
        • New-ADKcopype
      • Appx
      • Block
      • CloudDriver
      • Dell
        • Get-DellCatalogPC
        • Get-MyDellBIOS
        • Update-MyDellBios
      • Disk
        • Backup-Disk.ffu
        • Clear-LocalDisk
        • Clear-USBDisk
        • Get-LocalDisk
        • Get-OSDDisk
        • Get-USBDisk
        • New-OSDisk
          • Old Version
            • Sandbox
            • Partition Layout
            • Partition Sizes
            • Volume Labels
            • AutoUnattend.xml
        • Get-USBVolume
      • Dism
        • Get-MyWindowsCapability
        • Get-MyWindowsPackage
        • Set-WimExecutionPolicy
        • Set-WindowsImageExecutionPolicy
      • Display
        • Get-VidConRes
      • Driver
        • Get-OSDDriverWmiQ
        • Get-OSDDriver
      • General
        • Get-OSD
        • Get-OSDClass
        • Get-OSDGather
        • Get-OSDPower
        • Get-RegCurrentVersion
        • Get-SessionsXml
        • Save-OSDDownload
      • MyBitLocker
        • Get-MyBitLockerKeyProtectors
        • Backup-MyBitLocker
        • Save-MyBitLockerExternalKey
        • Save-MyBitLockerKeyPackage
        • Save-MyBitLockerRecoveryPassword
        • Unlock-MyBitLockerExternalKey
      • OOBE
      • PSModule
        • Copy-PSModuleToFolder
        • Copy-PSModuleToWim
        • Copy-PSModuleToWindowsImage
      • WebConnection
      • WebPSScript
      • WinPEWim
      • WinPE
        • Enable-PEWimPSGallery
        • Get-OSDWinPE
Powered by GitBook
On this page
  • Requirements
  • The Old Code
  • The New Code
  • The Block
  • The Build

Was this helpful?

  1. Docs
  2. Guides

New-OSDBoot.usb

PreviousIn Your CodeNextPartitions

Last updated 4 years ago

Was this helpful?

So I need to create a new function in the OSD Module to create a Dual Partition USB for OSDcloud. So this page will be the process of how I create one for the OSD Module. Keep in mind, by no means am I a PowerShell expert ... I'm still learning

Requirements

So here are the requirements for creating a New-OSDBoot.usb

  • Must run as Admin

  • Require Windows 10

  • PowerShell 5+

  • Windows 10 1703+

  • USB Drive > 8GB

    • 4GB ESD + some room for Drivers, etc

The Old Code

So I already have a script to handle the requirements, and I'm not trying to make you go blind, but this requires 92 lines. I used to copy/paste similar steps in new code, but that's not the point of the OSD Module

The New Code

As you can see I ended up putting all of those checks in new functions making things very easy to code in just 11 lines in the Function

function New-OSDBoot.usb {
    [CmdletBinding()]
    param ()
    Block-WinPE
    Block-NonAdmin
    Block-WindowsMajorLt10
    Block-PowerShellVersionLt5
    Block-WindowsReleaseIdLt1703
    $SelectUSBDisk = Select-USBDisk -MinimumSizeGB 8
    Return Get-USBDisk -Number $SelectUSBDisk.Number
}

The Block

The improvements continue when you look at the new Block functions in the #OSD Module by using PSCallStack, which really makes this small Block function easy to reuse in other Functions

function Block-NonAdmin {
    [CmdletBinding()]
    param ()
    $FirstParty = (Get-PSCallStack)[1].InvocationInfo.Line
    $Message = "[$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))] $FirstParty requires Admin Rights"

    if ((Get-OSDGather -Property IsAdmin) -eq $false) {
        Write-Warning $Message; Break
    }
}

The Build