#!/bin/pwsh $Global:InformationPreference = "Continue"; $Global:ErrorActionPreference = "Inquire"; $null = $env:WIN_COMPUTER_NAME; $null = $env:SETUP_SCRIPT_NAME; # Find `winiso` installation medium $drives = & wmic volume get "DriveLetter,Label"; $drive = $($($drives | Select-String -Pattern "winiso") -split "\s+")[0]; [xml]$unattendedConfig = [xml]::new(); $unattendedConfig.PreserveWhitespace = $true; $readerSettings = [System.Xml.XmlReaderSettings]::new(); $readerSettings.IgnoreComments = $true; $reader = [System.Xml.XmlReader]::Create("$PSScriptRoot/../Resources/Autounattend.template.xml", $readerSettings); $unattendedConfig.Load($reader); $namespace = New-Object -TypeName "Xml.XmlNamespaceManager" -ArgumentList $unattendedConfig.NameTable; $namespace.AddNamespace("ua", $unattendedConfig.DocumentElement.NamespaceURI); function Get-PassSettings { [OutputType([xml])] param( [string] $passName ) return $unattendedConfig.SelectSingleNode("/ua:unattend/ua:settings[@pass='$passName']", $namespace); } # Adjust unattended settings $specializeSettings = Get-PassSettings "specialize"; $specializeSettings.SelectSingleNode("./ua:component[@name='Microsoft-Windows-Shell-Setup']/ua:ComputerName", $namespace).InnerText = "$env:WIN_COMPUTER_NAME"; # Execute corresponding installer script after startup $oobeSystemSettings = Get-PassSettings "oobeSystem"; $installationCommand = $oobeSystemSettings.SelectSingleNode("./ua:component/ua:FirstLogonCommands/ua:SynchronousCommand[last()]", $namespace); $newCommand = $installationCommand.ParentNode.AppendChild($installationCommand.CloneNode($true)); $newCommand.SelectSingleNode("./ua:CommandLine", $namespace).InnerText = ` "powershell -Command " + ` $(Get-Content "$PSScriptRoot/InitialBoot.ps1") + ` "; pwsh '$([System.IO.Path]::GetRelativePath("$PSScriptRoot/../../..", $env:SETUP_SCRIPT_NAME))';"; $orderElement = $newCommand.SelectSingleNode("./ua:Order", $namespace); $orderElement.InnerText = ([int]($orderElement.InnerText) + 1); $newCommand.SelectSingleNode("./ua:Description", $namespace).InnerText = "Install PowerShell Core and git and run setup script"; if (Get-Command Initialize-SetupConfig -ErrorAction SilentlyContinue) { Initialize-SetupConfig $unattendedConfig $namespace; } $unattendedConfig.PreserveWhitespace = $true; $unattendedConfig.Save("$drive/Autounattend.xml"); Write-Warning "Attention: This program will completely wipe your current disk #1 and install Windows on it. Are you sure you want to do this?" Read-Host -Prompt "Hit enter to continue or CTRL+C to abort" & "$drive\setup.exe";