Private/Set-VHDUnattendFile.ps1

function Set-VHDUnattendFile {
    [CmdletBinding()]  
    param(
        [Parameter (Mandatory=$True)]
        [string]$VHDPath,

        [Parameter (Mandatory=$True)]
        [securestring]$UnattendAdminPassword,

        [Parameter (Mandatory=$True)]
        [string]$Locale,

        [Parameter (Mandatory=$True)]
        [string]$TimeZone
    )
    try {
        Set-ItemProperty -Path $VHDPath -Name IsReadOnly -Value $false
        $FileSystemDrives = Get-PSDrive -PSProvider FileSystem | Select-Object -ExpandProperty Name
        Mount-VHD -Path $VHDPath
        $MountedVHDDriveLetter = Get-PSDrive -PSProvider FileSystem | Select-Object -ExpandProperty Name | Where-Object {$_ -notin $FileSystemDrives}
        $UnattendPath = "$MountedVHDDriveLetter`:\Windows\System32\Sysprep\Unattend.xml"
            if ((Test-Path $UnattendPath) -ne $True) {
                $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($UnattendAdminPassword)
                $UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
                New-Item -Path $UnattendPath -Value (
'<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
    <settings pass="oobeSystem">
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <OOBE>
                <HideEULAPage>true</HideEULAPage>
            </OOBE>
            <UserAccounts>
                <AdministratorPassword>
                    <Value>{0}</Value>
                    <PlainText>true</PlainText>
                </AdministratorPassword>
            </UserAccounts>
            <TimeZone>{1}</TimeZone>
        </component>
        <component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <InputLocale>{2}</InputLocale>
            <SystemLocale>{2}</SystemLocale>
            <UILanguage>{2}</UILanguage>
            <UserLocale>{2}</UserLocale>
        </component>
    </settings>
</unattend>'
 -f $UnsecurePassword,$TimeZone,$Locale) | Out-Null
            }
    }
    catch {
        $PSCmdlet.ThrowTerminatingError($_)
    }
    finally {
        Dismount-VHD -Path $VHDPath -ErrorAction Stop
        Set-ItemProperty -Path $VHDPath -Name IsReadOnly -Value $True -ErrorAction Stop
    }
}