Good day!
I've created an autounattend.xml file with settings to skip OOBE, create user profile and running PowerShell script during first logon. First two worked fine except running the script. I've read many topics regarding this question, unfortunately none of them had working answer for me.
Here is an example of autounattend.xml:
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
<settings pass="offlineServicing" />
<settings pass="windowsPE">
<component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<SetupUILanguage>
<UILanguage>en-US</UILanguage>
</SetupUILanguage>
<InputLocale>0409:00000409</InputLocale>
<SystemLocale>en-US</SystemLocale>
<UILanguage>en-US</UILanguage>
<UserLocale>en-US</UserLocale>
</component>
</settings>
<settings pass="generalize" />
<settings pass="specialize" />
<settings pass="auditSystem" />
<settings pass="auditUser" />
<settings pass="oobeSystem">
<component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<InputLocale>0409:00000409</InputLocale>
<SystemLocale>en-US</SystemLocale>
<UILanguage>en-US</UILanguage>
<UserLocale>en-US</UserLocale>
</component>
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<UserAccounts>
<LocalAccounts>
<LocalAccount wcm:action="add">
<Name>Admin</Name>
<Group>Administrators</Group>
<Password>
<Value>mypassword</Value>
<PlainText>true</PlainText>
</Password>
</LocalAccount>
</LocalAccounts>
</UserAccounts>
<OOBE>
<HideEULAPage>true</HideEULAPage>
<ProtectYourPC>3</ProtectYourPC>
<HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
<NetworkLocation>Work</NetworkLocation>
</OOBE>
<FirstLogonCommands>
<SynchronousCommand wcm:action="add">
<CommandLine>FOR %i IN (C D E F G H I J K L N M) DO IF EXIST %i:\setup.ps1 Powershell -executionpolicy ByPass %i:\setup.ps1</CommandLine>
<Description>Setup</Description>
<Order>1</Order>
<RequiresUserInput>false</RequiresUserInput>
</SynchronousCommand>
</FirstLogonCommands>
</component>
</settings>
</unattend>
Would you please help me to figure that out?
Thank you!
===Updated===
The script is very simple. The contents of script:
For debug purposes i added strings with output to txt file in desktop and in C drive.
$machineName = (Get-WmiObject Win32_bios).SerialNumber
Rename-Computer $machineName
"Hello World!" | Out-File "C:\delete_me.txt"
"Hello World!" | Out-File "$($home)\Desktop\delete_me.txt"
That means that it does not work for normal and admin rights. Additionally setupact.log tries to run the script first and then creates the user. Can it be the issue?
2023-03-09 23:36:39, Info [Shell Unattend] Running 'oobeSystem' pass
2023-03-09 23:36:39, Info [Shell Unattend] LogonCommands: Set command 'FOR %i IN (C D E F G H I J K L N M) DO IF EXIST %i:\setup.ps1 Powershell -executionpolicy ByPass %i:\setup.ps1'
2023-03-09 23:36:39, Info [Shell Unattend] UserAccounts: created account 'User'
2023-03-09 23:36:39, Info [Shell Unattend] UserAccounts: added 'User2' to group 'Users'
2023-03-09 23:36:39, Info [Shell Unattend] UserAccounts: Password set for 'User'
2023-03-09 23:36:39, Info [Shell Unattend] UserAccounts: added 'User2' to group 'Administrators'
2023-03-09 23:36:39, Info [Shell Unattend] Exiting 'oobeSystem' pass with status 0x00000000