Skip to content

Instantly share code, notes, and snippets.

@babakc
Last active August 11, 2021 03:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save babakc/4d316c57527ac3db0664c8907497e4c9 to your computer and use it in GitHub Desktop.
Save babakc/4d316c57527ac3db0664c8907497e4c9 to your computer and use it in GitHub Desktop.
#Set my hostname based on my internal IP address
$instanceName = (((Invoke-WebRequest -UseBasicParsing -Uri http://169.254.169.254/latest/meta-data/hostname).Content).split(".")[0]).replace("ip-172-31","TCG")
#Change the hostname in the unattend.xml file
$filePath = "C:\Windows\Panther\Unattend.xml"
$AnswerFile = [xml](Get-Content -Path $filePath)
$ns = New-Object System.Xml.XmlNamespaceManager($answerFile.NameTable)
$ns.AddNamespace("ns", $AnswerFile.DocumentElement.NamespaceURI)
$ComputerName = $AnswerFile.SelectSingleNode('/ns:unattend/ns:settings[@pass="specialize"]/ns:component[@name="Microsoft-Windows-Shell-Setup"]/ns:ComputerName', $ns)
$ComputerName.InnerText = $InstanceName
$AnswerFile.Save($filePath)
#Start the OOBE
Start-Process C:\windows\system32\oobe\windeploy.exe -Wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment