Autounattend.xml中配置的PowerShell脚本无法在首次登录时运行的问题排查求助
大家好!我制作了一份autounattend.xml文件,配置了跳过OOBE、创建用户配置文件,以及在首次登录时运行PowerShell脚本的设置。前两项都正常工作,唯独运行脚本这部分始终没效果。我查了很多相关话题,但都没找到能解决我问题的方案。
以下是我的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>
希望各位能帮我找出问题所在,谢谢!
更新内容:
我的脚本其实很简单,为了调试,我加了输出到文本文件的内容,分别写到C盘和桌面:
$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"
但不管是普通权限还是管理员权限,脚本都没生效。另外我查看了setupact.log,发现日志里显示脚本是在用户创建之前就尝试运行的,这会不会是问题所在?
以下是日志片段:
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
备注:内容来源于stack exchange,提问作者Alex

