private/Step-BuildBootSetContentStartnet.ps1

#Requires -PSEdition Core

function Step-BuildBootSetContentStartnet {
    <#
    .SYNOPSIS
        Configures startnet.cmd and WinPEStartup directories in the mounted image
 
    .DESCRIPTION
        Replaces Windows\System32\startnet.cmd in the mounted image with a command file
        that sets a dated OSDCloud WinPEStartup title and invokes Invoke-WinPEStartup in
        Windows PowerShell. It also creates WinPEStartup\profiles and
        WinPEStartup\assets when those directories do not exist.
 
    .EXAMPLE
        PS> Step-BuildBootSetContentStartnet
 
        Writes the standard startup command and ensures its content directories exist.
 
    .INPUTS
        None. This function does not accept pipeline input.
 
    .OUTPUTS
        None.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Version: 0.1.0
        Date: 2026-08-28
 
        Requires global BuildMedia.MountPath. Destructively replaces startnet.cmd and
        may create directories in the mounted image. The generated command assumes
        Invoke-WinPEStartup will be available when WinPE starts.
    #>

    [CmdletBinding()]
    param ()

    $MountPath = $global:BuildMedia.MountPath
    $ScriptSource = $MyInvocation.MyCommand.Name

    $BuildDate = Get-Date -Format 'yy.M.d'
$startnetCmd = @"
@echo off
title OSDCloud WinPEStartup $BuildDate (close window to restart computer)
PowerShell -Nol -C Invoke-WinPEStartup
"@

    $startnetCmdPath = "$MountPath\Windows\System32\startnet.cmd"
    Write-Host -ForegroundColor DarkGray "[$(Get-Date -format s)] [INFO] [$ScriptSource] Adding $startnetCmdPath"
    $startnetCmd | Out-File -FilePath $startnetCmdPath -Encoding ascii -Width 2000 -Force

    if (-not (Test-Path "$MountPath\WinPEStartup\profiles")) {
        Write-Host -ForegroundColor DarkGray "[$(Get-Date -format s)] [INFO] [$ScriptSource] Creating directory $MountPath\WinPEStartup\profiles"
        New-Item -Path "$MountPath\WinPEStartup\profiles" -ItemType Directory -Force | Out-Null
    }
    if (-not (Test-Path "$MountPath\WinPEStartup\assets")) {
        Write-Host -ForegroundColor DarkGray "[$(Get-Date -format s)] [INFO] [$ScriptSource] Creating directory $MountPath\WinPEStartup\assets"
        New-Item -Path "$MountPath\WinPEStartup\assets" -ItemType Directory -Force | Out-Null
    }
}