I have been told that it is possible to run Powershell directly from the Unattend.xml during an OS install.
I am trying to set the ComputerName to (A + "SerialNumber") but not matter how I write the file it keeps being stepped over.
Currently I have the XML as below
<settings pass="specialize">
<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>en-IE</InputLocale>
<SystemLocale>en-IE</SystemLocale>
<UILanguage>en-IE</UILanguage>
<UserLocale>en-IE</UserLocale>
<UILanguageFallback></UILanguageFallback>
</component>
<component name="Microsoft-Windows-Deployment" 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">
<RunAsynchronous>
<RunAsynchronousCommand wcm:action="add">
<Path>powershell.exe –ExecutionPolicy Bypass -File "\\server\store\Software\Powershell\UnattendedInstallComputerName.ps1"</Path>
<Description>Use script to rename computer with Serial number</Description>
<Order>1</Order>
</RunAsynchronousCommand>
</RunAsynchronous>
</component>
</settings>
<settings pass="oobeSystem">
<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>en-IE</InputLocale>
<SystemLocale>en-IE</SystemLocale>
<UILanguage>en-IE</UILanguage>
<UserLocale>en-IE</UserLocale>
</component>
</settings>
With the script being called simply as
$Serial = Get-WmiObject win32_bios | select -expand serialnumber
$CompName = "A" + $Serial
Rename-Computer $CompName
Now I have done loads of variants of the above in different pass runs but no luck. I've honestly just thrown the "powershell.exe –ExecutionPolicy Bypass -File " as a Hail Mary.
Any help would be appreciated
I got this working with windows 10 pro As a note :Synchronous Commands in the Specialize Stage Appear to Run BEFORE other sections in the same stage. So if you have a PC name specified in WDS client naming policy and have the xml configured to rename, then you'll run into that issue.
ProTip (After a deployment go to C:\windows\panther\UnattendGC\setupact.log to review what was processed and when.)
I recommend running the pc rename in the oobe stage.
Also commands to be executed have a max length of ~250 characters total. It says ~1000, but I've tried with powershell commands that were ~500 chars and they silent fail.
In short try this command in the oobe stage: C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -noprofile -command "Start-Transcript;(Get-WmiObject win32_computersystem).Rename((Get-WmiObject 'win32_bios').serialnumber.trim());Stop-Transcript"
Note that this xml also contains a structure for domain joining in the oobe stage which as worked for me. If you're security conscious create a wds domain joining account, just for that purpose that controls a specific OUs computer objects (there are guides for this), and just change the password on your domain join service account after a mass deployment. You can quickly update the password in the xml and reimport on your WDS server when you have another bulk deploy operation.
XML for reference...