> For the complete documentation index, see [llms.txt](https://osd.osdeploy.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://osd.osdeploy.com/docs/guides/new-osdboot.usb.md).

# 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

![](https://3420392058-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LpnxLqvh8u2fEz86kIM%2F-MW1aQVM9NoZ8BD2eHni%2F-MW2LefLPO1sIHQS6Ss7%2Fimage.png?alt=media\&token=cfd9a742-2869-4f3e-8e76-5f2139b6de3d)

### 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
}
```

![](https://3420392058-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LpnxLqvh8u2fEz86kIM%2F-MW1aQVM9NoZ8BD2eHni%2F-MW2MpUgd2FW2h7jGKfz%2Fimage.png?alt=media\&token=6de924aa-01b0-4ef7-af3e-6dd220409341)

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

![](https://3420392058-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LpnxLqvh8u2fEz86kIM%2F-MW1aQVM9NoZ8BD2eHni%2F-MW2NLReTNQhGuQZfJAh%2Fimage.png?alt=media\&token=146eeed6-da58-4cc6-8bc5-885ad7446a60)

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