New-OSDBoot.usb
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
1
function New-OSDBoot.usb {
2
[CmdletBinding()]
3
param ()
4
Block-WinPE
5
Block-NonAdmin
6
Block-WindowsMajorLt10
7
Block-PowerShellVersionLt5
8
Block-WindowsReleaseIdLt1703
9
$SelectUSBDisk = Select-USBDisk -MinimumSizeGB 8
10
Return Get-USBDisk -Number $SelectUSBDisk.Number
11
}
Copied!

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
1
function Block-NonAdmin {
2
[CmdletBinding()]
3
param ()
4
$FirstParty = (Get-PSCallStack)[1].InvocationInfo.Line
5
$Message = "[$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))] $FirstParty requires Admin Rights"
6
7
if ((Get-OSDGather -Property IsAdmin) -eq $false) {
8
Write-Warning $Message; Break
9
}
10
}
Copied!

The Build

Last modified 8mo ago