![如何在 autounattend.xml 檔案中從安裝媒體運行腳本?](https://rvso.com/image/1618751/%E5%A6%82%E4%BD%95%E5%9C%A8%20autounattend.xml%20%E6%AA%94%E6%A1%88%E4%B8%AD%E5%BE%9E%E5%AE%89%E8%A3%9D%E5%AA%92%E9%AB%94%E9%81%8B%E8%A1%8C%E8%85%B3%E6%9C%AC%EF%BC%9F.png)
我製作了一些 PowerShell (.ps1) 和批次 (.bat) 腳本,我希望將它們作為自動化 Windows 安裝的一部分。我已經使用 Windows 系統映像管理員配置了 autounattend.xml 檔案中的其他所有內容,除了執行我的腳本之外,它運作得很好。
在嘗試完全自動化之前,我曾經繞過 OOBE 進入審核模式 (CTRL+SHIFT+F3),然後從那裡運行我的腳本。在知道我的腳本在 Windows 系統映像管理員中的審核模式下運作後,我決定在第 6 關audituser 處插入同步命令。
到目前為止,這是我的 autouattend.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="oobeSystem">
<component name="Microsoft-Windows-Shell-Setup" 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">
<AutoLogon>
<Password>
<Value>cABhAHMAcwB3AG8AcgBkAFAAYQBzAHMAdwBvAHIAZAA=</Value>
<PlainText>false</PlainText>
</Password>
<Enabled>true</Enabled>
<LogonCount>3</LogonCount>
<Username>LocalAdmin</Username>
</AutoLogon>
<UserAccounts>
<LocalAccounts>
<LocalAccount wcm:action="add">
<Password>
<Value>cABhAHMAcwB3AG8AcgBkAFAAYQBzAHMAdwBvAHIAZAA=</Value>
<PlainText>false</PlainText>
</Password>
<Name>LocalAdmin</Name>
<Group>Administrators</Group>
<DisplayName></DisplayName>
<Description>Local adminstrator stored on the system drive</Description>
</LocalAccount>
</LocalAccounts>
</UserAccounts>
<OOBE>
<SkipMachineOOBE>true</SkipMachineOOBE>
<SkipUserOOBE>true</SkipUserOOBE>
<HideOnlineAccountScreens>true</HideOnlineAccountScreens>
<HideEULAPage>true</HideEULAPage>
</OOBE>
</component>
</settings>
<settings pass="windowsPE">
<component name="Microsoft-Windows-Setup" 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">
<EnableNetwork>false</EnableNetwork>
<DiskConfiguration>
<Disk wcm:action="add">
<CreatePartitions>
<CreatePartition wcm:action="add">
<Order>1</Order>
<Size>500</Size>
<Type>Primary</Type>
</CreatePartition>
<CreatePartition wcm:action="add">
<Order>2</Order>
<Type>EFI</Type>
<Size>100</Size>
</CreatePartition>
<CreatePartition wcm:action="add">
<Order>4</Order>
<Extend>true</Extend>
<Type>Primary</Type>
</CreatePartition>
<CreatePartition wcm:action="add">
<Order>3</Order>
<Size>16</Size>
<Type>MSR</Type>
</CreatePartition>
</CreatePartitions>
<ModifyPartitions>
<ModifyPartition wcm:action="add">
<Format>NTFS</Format>
<Label></Label>
<Order>1</Order>
<PartitionID>1</PartitionID>
<TypeID>DE94BBA4-06D1-4D40-A16A-BFD50179D6AC</TypeID>
</ModifyPartition>
<ModifyPartition wcm:action="add">
<Order>2</Order>
<Format>FAT32</Format>
<PartitionID>2</PartitionID>
<Label>System</Label>
</ModifyPartition>
<ModifyPartition wcm:action="add">
<PartitionID>3</PartitionID>
<Order>3</Order>
</ModifyPartition>
<ModifyPartition wcm:action="add">
<PartitionID>4</PartitionID>
<Order>4</Order>
<Format>NTFS</Format>
</ModifyPartition>
</ModifyPartitions>
<WillWipeDisk>true</WillWipeDisk>
<DiskID>0</DiskID>
</Disk>
</DiskConfiguration>
<ImageInstall>
<OSImage>
<InstallTo>
<DiskID>0</DiskID>
<PartitionID>4</PartitionID>
</InstallTo>
<InstallFrom>
<MetaData wcm:action="add">
<Key>/IMAGE/NAME</Key>
<Value>Windows 10 Pro</Value>
</MetaData>
</InstallFrom>
</OSImage>
</ImageInstall>
<UserData>
<ProductKey>
<WillShowUI>OnError</WillShowUI>
<Key />
</ProductKey>
<AcceptEula>true</AcceptEula>
</UserData>
</component>
<component name="Microsoft-Windows-International-Core-WinPE" 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">
<SetupUILanguage>
<UILanguage>en-gb</UILanguage>
</SetupUILanguage>
<InputLocale>en-gb</InputLocale>
<SystemLocale>en-gb</SystemLocale>
<UILanguageFallback>en-us</UILanguageFallback>
<UILanguage>en-gb</UILanguage>
</component>
</settings>
<settings pass="auditUser">
<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">
<RunSynchronous>
<RunSynchronousCommand wcm:action="add">
<Order>2</Order>
<Path>powershell.exe -executionpolicy remotesigned -File "Files\Scripts\2A-Create_Daily_System_Restore_Point.ps1"</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Remove Windows Bloatware Provisioned Apps</Description>
<Order>1</Order>
<Path>powershell.exe -executionpolicy remotesigned -File "%~dp0\Files\Scripts\1-Remove_Bloatware_Apps.ps1"</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Order>3</Order>
<Path>cmd.exe /c %~dp0\Files\Scripts\3-Remove_Folders_from_This_PC.bat</Path>
</RunSynchronousCommand>
</RunSynchronous>
</component>
</settings>
<cpi:offlineImage cpi:source="wim:d:/users/will/documents/it%20projects/windows%2010%20image/install.wim#Windows 10 Home" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
</unattend>
我將在 Windows 安裝媒體的根目錄中放置一個名為「Scripts」的目錄,因此我的問題是,如何從安裝媒體的 autounattend.xml 中呼叫這些腳本?是否有一個變數連結到安裝媒體所在的磁碟機和路徑?
答案1
我想我已經找到了解決方案。
- 將 ISO/Windows 安裝媒體解壓縮到資料夾中
sources\
在提取的安裝媒體的目錄中建立一個資料夾,名為$OEM$- 鏡像系統驅動器,以便您擁有具有以下路徑的目錄
sources\$OEM$\$$\Setup\Scripts
(C:\Windows\安裝程式\腳本)
$OEM$ 資料夾鏡像系統驅動器,因此這些資料夾中的所有內容都會在安裝過程中複製。對於從 autounattend.xml 檔案執行的腳本,您只需從以下位置呼叫腳本即可%SystemDrive%\WinDir\Setup\Scripts
更多資訊可以在這裡找到>https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-8.1-and-8/hh825027%28v%3dwin.10%29
答案2
Afaik,auditUser
除非系統進入審核模式,否則在 Windows 安裝過程中不會執行該通行證。因此,除了您的解決方案之外,還有其他兩種可能的解決方案:
- 將您的命令放入
specialize
pass 或oobeSystem
pass 中。通常,安裝媒體會被指派 letterX:
,但如果您想確保安裝程式能夠找到腳本,您可以使用下列條件:
<RunSynchronousCommand wcm:action="add">
<Description>Run script</Description>
<Order>1</Order>
<!-- Enumerate through all drives looking for the MYIT_OEMBypass.ps1 script, if found, run it. Leave the command prompt open. -->
<Path>cmd /c "(FOR %i IN (C D E F G H I J K L N M) DO IF EXIST %i:\MYIT_OEMBypass.ps1 Powershell -executionpolicy ByPass %i:\MYIT_OEMBypass.ps1) & pause"</Path>
</RunSynchronousCommand>
oobeSystem
當傳遞開始執行時,透過輸入以下內容指示 Windows 安裝程式直接執行到審核模式 (sysprep) :
<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">
<Reseal>
<Mode>Audit</Mode>
<ForceShutdownNow>false</ForceShutdownNow>
</Reseal>
</component>
使用這種方法,您能保持你的命令auditUser
通過了。這也有助於設定包含所有您喜歡的調整的預設設定文件,因此以後創建的任何設定檔也將套用所有這些調整。
然而,預設情況下,汽車unattend.xml 將被複製並設定為 sysprep 的 unattend.xml 腳本,這顯然會導致問題。因此,您需要進行一些小的更改來指示 sysprep 使用不同的無人值守.xml。有關此方法的更詳細指南可以在此處找到: https://rzander.azurewebsites.net/modern-os-deployment-mosd/