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
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
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

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 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
}
}
Last modified 2yr ago