private/BootMedia/Steps/Step-BootImageSetStartnet.ps1

#Requires -PSEdition Core

function Step-BootImageSetStartnet {
    <#
    .SYNOPSIS
        Writes startnet.cmd and creates WinPEStartup directories in the mounted WinPE image.
 
    .NOTES
        Author: David Segura
        Version: 0.1.0
    #>

    [CmdletBinding()]
    param ()

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

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

    $startnetCmdPath = "$MountPath\Windows\System32\startnet.cmd"
    Write-Host -ForegroundColor DarkGray "[$(Get-Date -format G)] [$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 G)] [$ScriptSource] Creating directory $MountPath\WinPEStartup\Profiles"
        New-Item -Path "$MountPath\WinPEStartup\Profiles" -ItemType Directory -Force | Out-Null
    }
    if (-not (Test-Path "$MountPath\WinPEStartup\Scripts")) {
        Write-Host -ForegroundColor DarkGray "[$(Get-Date -format G)] [$ScriptSource] Creating directory $MountPath\WinPEStartup\Scripts"
        New-Item -Path "$MountPath\WinPEStartup\Scripts" -ItemType Directory -Force | Out-Null
    }
}