当前位置:   article > 正文

使用Packer在Hyper-V上自动部署Windows Server 2016中文版_sw dvd9 win svr std core and datactr core 2016 64b

sw dvd9 win svr std core and datactr core 2016 64bit chnsimp-2mlf x21-22842.

WindowsServer.Json

  1. {
  2. "builders": [
  3. {
  4. "type": "hyperv-iso",
  5. "communicator": "winrm",
  6. "disk_size": 61440,
  7. "memory": 2048,
  8. "floppy_files": [
  9. "{{template_dir}}/setup/"
  10. ],
  11. "guest_additions_mode": "disable",
  12. "headless": false,
  13. "iso_url": "file://F:\\SOFTWARE\\SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_ChnSimp_-2_MLF_X21-22842.iso",
  14. "iso_checksum": "c1f8c8325e88f4687eabc4c60a6c3fcb",
  15. "winrm_username": "vagrant",
  16. "winrm_password": "vagrant",
  17. "winrm_timeout": "6h"
  18. }
  19. ],
  20. "provisioners": [
  21. {
  22. "type": "windows-shell",
  23. "inline": ["dir c:\\"]
  24. }
  25. ]
  26. }

Autounattend.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <unattend xmlns="urn:schemas-microsoft-com:unattend">
  3. <settings pass="windowsPE">
  4. <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">
  5. <SetupUILanguage>
  6. <UILanguage>zh-CN</UILanguage>
  7. </SetupUILanguage>
  8. <InputLocale>zh-CN</InputLocale>
  9. <SystemLocale>zh-CN</SystemLocale>
  10. <UILanguage>zh-CN</UILanguage>
  11. <UILanguageFallback>zh-CN</UILanguageFallback>
  12. <UserLocale>zh-CN</UserLocale>
  13. </component>
  14. <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">
  15. <DiskConfiguration>
  16. <Disk wcm:action="add">
  17. <CreatePartitions>
  18. <CreatePartition wcm:action="add">
  19. <Type>Primary</Type>
  20. <Order>1</Order>
  21. <Size>350</Size>
  22. </CreatePartition>
  23. <CreatePartition wcm:action="add">
  24. <Order>2</Order>
  25. <Type>Primary</Type>
  26. <Extend>true</Extend>
  27. </CreatePartition>
  28. </CreatePartitions>
  29. <ModifyPartitions>
  30. <ModifyPartition wcm:action="add">
  31. <Active>true</Active>
  32. <Format>NTFS</Format>
  33. <Label>boot</Label>
  34. <Order>1</Order>
  35. <PartitionID>1</PartitionID>
  36. </ModifyPartition>
  37. <ModifyPartition wcm:action="add">
  38. <Format>NTFS</Format>
  39. <Label>Windows 2016</Label>
  40. <Letter>C</Letter>
  41. <Order>2</Order>
  42. <PartitionID>2</PartitionID>
  43. </ModifyPartition>
  44. </ModifyPartitions>
  45. <DiskID>0</DiskID>
  46. <WillWipeDisk>true</WillWipeDisk>
  47. </Disk>
  48. </DiskConfiguration>
  49. <ImageInstall>
  50. <OSImage>
  51. <InstallFrom>
  52. <MetaData wcm:action="add">
  53. <Key>/IMAGE/NAME</Key>
  54. <Value>Windows Server 2016 SERVERDATACENTER</Value>
  55. </MetaData>
  56. </InstallFrom>
  57. <InstallTo>
  58. <DiskID>0</DiskID>
  59. <PartitionID>2</PartitionID>
  60. </InstallTo>
  61. </OSImage>
  62. </ImageInstall>
  63. <UserData>
  64. <!-- Product Key from https://www.microsoft.com/de-de/evalcenter/evaluate-windows-server-technical-preview?i=1 -->
  65. <ProductKey>
  66. <!-- Do not uncomment the Key element if you are using trial ISOs -->
  67. <!-- You must uncomment the Key element (and optionally insert your own key) if you are using retail or volume license ISOs -->
  68. <Key>6CNGG-BJP34-H923Y-6DMWR-37BMF</Key>
  69. <WillShowUI>OnError</WillShowUI>
  70. </ProductKey>
  71. <AcceptEula>true</AcceptEula>
  72. <FullName>Vagrant</FullName>
  73. <Organization>Vagrant</Organization>
  74. </UserData>
  75. </component>
  76. </settings>
  77. <settings pass="specialize">
  78. <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">
  79. <OEMInformation>
  80. <HelpCustomized>false</HelpCustomized>
  81. </OEMInformation>
  82. <ComputerName>vagrant-2016</ComputerName>
  83. <TimeZone>China Standard Time</TimeZone>
  84. <RegisteredOwner/>
  85. </component>
  86. <component name="Microsoft-Windows-ServerManager-SvrMgrNc" 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">
  87. <DoNotOpenServerManagerAtLogon>true</DoNotOpenServerManagerAtLogon>
  88. </component>
  89. <component name="Microsoft-Windows-IE-ESC" 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">
  90. <IEHardenAdmin>false</IEHardenAdmin>
  91. <IEHardenUser>false</IEHardenUser>
  92. </component>
  93. <component name="Microsoft-Windows-OutOfBoxExperience" 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">
  94. <DoNotOpenInitialConfigurationTasksAtLogon>true</DoNotOpenInitialConfigurationTasksAtLogon>
  95. </component>
  96. <component name="Microsoft-Windows-Security-SPP-UX" 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">
  97. <SkipAutoActivation>true</SkipAutoActivation>
  98. </component>
  99. <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">
  100. <RunSynchronous>
  101. <RunSynchronousCommand wcm:action="add">
  102. <Order>1</Order>
  103. <Description>Set Execution Policy 64 Bit</Description>
  104. <Path>cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</Path>
  105. </RunSynchronousCommand>
  106. <RunSynchronousCommand wcm:action="add">
  107. <Order>2</Order>
  108. <Description>Set Execution Policy 32 Bit</Description>
  109. <Path>cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</Path>
  110. </RunSynchronousCommand>
  111. <!-- <RunSynchronousCommand wcm:action="add">
  112. <Order>3</Order>
  113. <Description>Disable WinRM</Description>
  114. <Path>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\disable-winrm.ps1</Path>
  115. </RunSynchronousCommand> -->
  116. </RunSynchronous>
  117. </component>
  118. </settings>
  119. <settings pass="oobeSystem">
  120. <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">
  121. <AutoLogon>
  122. <Password>
  123. <Value>vagrant</Value>
  124. <PlainText>true</PlainText>
  125. </Password>
  126. <Enabled>true</Enabled>
  127. <Username>vagrant</Username>
  128. </AutoLogon>
  129. <FirstLogonCommands>
  130. <SynchronousCommand wcm:action="add">
  131. <Order>1</Order>
  132. <CommandLine>cmd.exe /c a:\vmtools.cmd</CommandLine>
  133. <RequiresUserInput>true</RequiresUserInput>
  134. </SynchronousCommand>
  135. </FirstLogonCommands>
  136. <OOBE>
  137. <HideEULAPage>true</HideEULAPage>
  138. <HideLocalAccountScreen>true</HideLocalAccountScreen>
  139. <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>
  140. <HideOnlineAccountScreens>true</HideOnlineAccountScreens>
  141. <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
  142. <NetworkLocation>Home</NetworkLocation>
  143. <ProtectYourPC>1</ProtectYourPC>
  144. </OOBE>
  145. <UserAccounts>
  146. <AdministratorPassword>
  147. <Value>vagrant</Value>
  148. <PlainText>true</PlainText>
  149. </AdministratorPassword>
  150. <LocalAccounts>
  151. <LocalAccount wcm:action="add">
  152. <Password>
  153. <Value>vagrant</Value>
  154. <PlainText>true</PlainText>
  155. </Password>
  156. <Group>administrators</Group>
  157. <DisplayName>Vagrant</DisplayName>
  158. <Name>vagrant</Name>
  159. <Description>Vagrant User</Description>
  160. </LocalAccount>
  161. </LocalAccounts>
  162. </UserAccounts>
  163. <RegisteredOwner />
  164. </component>
  165. </settings>
  166. <settings pass="offlineServicing">
  167. <component name="Microsoft-Windows-LUA-Settings" 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">
  168. <EnableLUA>false</EnableLUA>
  169. </component>
  170. </settings>
  171. <cpi:offlineImage cpi:source="wim:c:/wim/install.wim#Windows Server 2012 R2 SERVERSTANDARD" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
  172. </unattend>

输出:

  1. F:\packer-hyperv-win2016>packer.exe build WindowsServer.Json
  2. Warning: Warning when preparing build: "hyperv-iso"
  3. A shutdown_command was not specified. Without a shutdown command, Packer will forcibly halt the virtual machine, which may result in data loss. hyperv-iso: output will be in this color. ==> hyperv-iso: Creating build directory... ==> hyperv-iso: Retrieving ISO
  4. ==> hyperv-iso: Trying file://F:\SOFTWARE\SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_ChnSimp_-2_MLF_X21-22842.iso
  5. ==> hyperv-iso: Trying file://F:/SOFTWARE/SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_ChnSimp_-2_MLF_X21-22842.iso?checksum=md5%3Ac1f8c8325e88f4687eabc4c60a6c3fcb
  6. ==> hyperv-iso: file://F:/SOFTWARE/SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_ChnSimp_-2_MLF_X21-22842.iso?checksum=md5%3Ac1f8c8325e88f4687eabc4c60a6c3fcb => F:/SOFTWARE/SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_ChnSimp_-2_MLF_X21-22842.iso ==> hyperv-iso: Creating floppy disk... hyperv-iso: Copying files flatly from floppy_files hyperv-iso: Copying directory: F:\packer-hyperv-win2016/setup/ hyperv-iso: Adding file: F:\packer-hyperv-win2016\setup\Autounattend.xml
  7. hyperv-iso: Adding file: F:\packer-hyperv-win2016\setup\vmtools.cmd
  8. hyperv-iso: Done copying files from floppy_files
  9. hyperv-iso: Collecting paths from floppy_dirs hyperv-iso: Resulting paths from floppy_dirs : [] hyperv-iso: Done copying paths from floppy_dirs hyperv-iso: Copying files from floppy_content hyperv-iso: Done copying files from floppy_content ==> hyperv-iso: Creating switch 'packer-hyperv-iso' if required...
  10. ==> hyperv-iso: switch 'packer-hyperv-iso' already exists. Will not delete on cleanup...
  11. ==> hyperv-iso: Creating virtual machine...
  12. ==> hyperv-iso: Enabling Integration Service...
  13. ==> hyperv-iso: Mounting os dvd drive F:/SOFTWARE/SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_ChnSimp_-2_MLF_X21-22842.iso ...
  14. ==> hyperv-iso: Mounting floppy drive...
  15. ==> hyperv-iso: Skipping mounting Integration Services Setup Disk...
  16. ==> hyperv-iso: Mounting secondary DVD images...
  17. ==> hyperv-iso: Configuring vlan...
  18. ==> hyperv-iso: Determine Host IP for HyperV machine...
  19. ==> hyperv-iso: Host IP for the HyperV machine: 169.254.10.91
  20. ==> hyperv-iso: Attempting to connect with vmconnect...
  21. ==> hyperv-iso: Starting the virtual machine...
  22. ==> hyperv-iso: Waiting 10s for boot...
  23. ==> hyperv-iso: Typing the boot command...
  24. ==> hyperv-iso: Waiting for WinRM to become available...
  25. Cancelling build after receiving interrupt
  26. ==> hyperv-iso: Disconnecting from vmconnect...
  27. ==> hyperv-iso: Cleanup floppy drive...
  28. ==> hyperv-iso: Clean up os dvd drive...
  29. ==> hyperv-iso: Unregistering and deleting virtual machine...
  30. ==> hyperv-iso: Deleting output directory...
  31. ==> hyperv-iso: Deleting build directory...
  32. Build 'hyperv-iso' errored after 8 minutes 51 seconds: Build was cancelled.
  33. ==> Wait completed after 8 minutes 51 seconds
  34. Cleanly cancelled builds after being interrupted.
  35. F:\packer-hyperv-win2016>packer.exe build WindowsServer.Json
  36. Warning: Warning when preparing build: "hyperv-iso"
  37. A shutdown_command was not specified. Without a shutdown command, Packer
  38. will forcibly halt the virtual machine, which may result in data loss.
  39. hyperv-iso: output will be in this color. ==> hyperv-iso: Creating build directory... ==> hyperv-iso: Retrieving ISO
  40. ==> hyperv-iso: Trying file://F:\SOFTWARE\SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_ChnSimp_-2_MLF_X21-22842.iso
  41. ==> hyperv-iso: Trying file://F:/SOFTWARE/SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_ChnSimp_-2_MLF_X21-22842.iso?checksum=md5%3Ac1f8c8325e88f4687eabc4c60a6c3fcb
  42. ==> hyperv-iso: file://F:/SOFTWARE/SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_ChnSimp_-2_MLF_X21-22842.iso?checksum=md5%3Ac1f8c8325e88f4687eabc4c60a6c3fcb => F:/SOFTWARE/SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_ChnSimp_-2_MLF_X21-22842.iso ==> hyperv-iso: Creating floppy disk... hyperv-iso: Copying files flatly from floppy_files hyperv-iso: Copying directory: F:\packer-hyperv-win2016/setup/ hyperv-iso: Adding file: F:\packer-hyperv-win2016\setup\Autounattend.xml
  43. hyperv-iso: Adding file: F:\packer-hyperv-win2016\setup\vmtools.cmd
  44. hyperv-iso: Done copying files from floppy_files
  45. hyperv-iso: Collecting paths from floppy_dirs
  46. hyperv-iso: Resulting paths from floppy_dirs : []
  47. hyperv-iso: Done copying paths from floppy_dirs
  48. hyperv-iso: Copying files from floppy_content
  49. hyperv-iso: Done copying files from floppy_content
  50. ==> hyperv-iso: Creating switch 'packer-hyperv-iso' if required...
  51. ==> hyperv-iso: switch 'packer-hyperv-iso' already exists. Will not delete on cleanup...
  52. ==> hyperv-iso: Creating virtual machine...
  53. ==> hyperv-iso: Enabling Integration Service...
  54. ==> hyperv-iso: Mounting os dvd drive F:/SOFTWARE/SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_ChnSimp_-2_MLF_X21-22842.iso ...
  55. ==> hyperv-iso: Mounting floppy drive...
  56. ==> hyperv-iso: Skipping mounting Integration Services Setup Disk...
  57. ==> hyperv-iso: Mounting secondary DVD images...
  58. ==> hyperv-iso: Configuring vlan...
  59. ==> hyperv-iso: Determine Host IP for HyperV machine... ==> hyperv-iso: Host IP for the HyperV machine: 169.254.10.91 ==> hyperv-iso: Attempting to connect with vmconnect... ==> hyperv-iso: Starting the virtual machine... ==> hyperv-iso: Waiting 10s for boot... ==> hyperv-iso: Typing the boot command...
  60. ==> hyperv-iso: Waiting for WinRM to become available...
  61. hyperv-iso: WinRM connected. ==> hyperv-iso: Connected to WinRM! ==> hyperv-iso: Provisioning with windows-shell... ==> hyperv-iso: Provisioning with shell script: C:\Users\ADMINI~1\AppData\Local\Temp\windows-shell-provisioner3533260373 hyperv-iso: hyperv-iso: C:\Users\vagrant>dir c:\ hyperv-iso: Volume in drive C is Windows 2016 hyperv-iso: Volume Serial Number is 2657-24CA hyperv-iso:
  62. hyperv-iso: Directory of c:\
  63. hyperv-iso:
  64. hyperv-iso: 2016/09/12 20:45 <DIR> Logs
  65. hyperv-iso: 2016/07/16 21:23 <DIR> PerfLogs
  66. hyperv-iso: 2016/09/12 20:45 <DIR> Program Files
  67. hyperv-iso: 2016/07/16 21:23 <DIR> Program Files (x86)
  68. hyperv-iso: 2021/12/25 10:59 <DIR> Users
  69. hyperv-iso: 2021/12/25 10:58 <DIR> Windows
  70. hyperv-iso: 0 File(s) 0 bytes
  71. hyperv-iso: 6 Dir(s) 53,121,290,240 bytes free
  72. ==> hyperv-iso: Forcibly halting virtual machine...
  73. ==> hyperv-iso: Waiting for vm to be powered down...
  74. ==> hyperv-iso: Unmount/delete secondary dvd drives...
  75. ==> hyperv-iso: Unmount/delete Integration Services dvd drive...
  76. ==> hyperv-iso: Unmount/delete os dvd drive...
  77. ==> hyperv-iso: Delete os dvd drives controller 0 location 1 ...
  78. ==> hyperv-iso: Unmount/delete floppy drive (Run)...
  79. ==> hyperv-iso: Compacting disks...
  80. hyperv-iso: Compacting disk: packer-hyperv-iso.vhdx
  81. hyperv-iso: Disk size reduced by: .3%
  82. ==> hyperv-iso: Exporting virtual machine...
  83. ==> hyperv-iso: Collating build artifacts...
  84. ==> hyperv-iso: Disconnecting from vmconnect...
  85. ==> hyperv-iso: Cleanup floppy drive...
  86. ==> hyperv-iso: Unregistering and deleting virtual machine...
  87. ==> hyperv-iso: Deleting build directory...
  88. Build 'hyperv-iso' finished after 18 minutes 38 seconds.
  89. ==> Wait completed after 18 minutes 38 seconds
  90. ==> Builds finished. The artifacts of successful builds are:
  91. --> hyperv-iso: VM files in directory: output-hyperv-iso
  92. F:\packer-hyperv-win2016>

Hyper-V 2代硬件中删除了软盘,需要使用光盘提供自动应答文件:

  1. {
  2. "builders": [
  3. {
  4. "type": "hyperv-iso",
  5. "communicator": "winrm",
  6. "disk_size": 61440,
  7. "memory": 2048,
  8. "secondary_iso_images": [
  9. "./setup/setup.iso"
  10. ],
  11. "generation": 2,
  12. "guest_additions_mode": "disable",
  13. "headless": false,
  14. "iso_url": "file://F:\\SOFTWARE\\SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_ChnSimp_-2_MLF_X21-22842.iso",
  15. "iso_checksum": "c1f8c8325e88f4687eabc4c60a6c3fcb",
  16. "winrm_username": "vagrant",
  17. "winrm_password": "vagrant",
  18. "winrm_timeout": "6h"
  19. }
  20. ],
  21. "provisioners": [
  22. {
  23. "type": "windows-shell",
  24. "inline": ["dir c:\\"]
  25. }
  26. ]
  27. }

Autounattend.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <unattend xmlns="urn:schemas-microsoft-com:unattend">
  3. <settings pass="windowsPE">
  4. <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
  5. <SetupUILanguage>
  6. <UILanguage>en-US</UILanguage>
  7. </SetupUILanguage>
  8. <InputLocale>en-US</InputLocale>
  9. <SystemLocale>en-US</SystemLocale>
  10. <UILanguage>en-US</UILanguage>
  11. <UILanguageFallback>en-US</UILanguageFallback>
  12. <UserLocale>en-US</UserLocale>
  13. </component>
  14. <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
  15. <DiskConfiguration>
  16. <Disk wcm:action="add">
  17. <CreatePartitions>
  18. <CreatePartition wcm:action="add">
  19. <Order>1</Order>
  20. <Size>500</Size>
  21. <Type>EFI</Type>
  22. </CreatePartition>
  23. <CreatePartition wcm:action="add">
  24. <Order>2</Order>
  25. <Size>128</Size>
  26. <Type>MSR</Type>
  27. </CreatePartition>
  28. <CreatePartition wcm:action="add">
  29. <Order>3</Order>
  30. <Extend>true</Extend>
  31. <Type>Primary</Type>
  32. </CreatePartition>
  33. </CreatePartitions>
  34. <DiskID>0</DiskID>
  35. <WillWipeDisk>true</WillWipeDisk>
  36. </Disk>
  37. </DiskConfiguration>
  38. <ImageInstall>
  39. <OSImage>
  40. <InstallFrom>
  41. <MetaData wcm:action="add">
  42. <Key>/IMAGE/NAME</Key>
  43. <Value>Windows Server 2016 SERVERDATACENTER</Value>
  44. </MetaData>
  45. </InstallFrom>
  46. <InstallTo>
  47. <DiskID>0</DiskID>
  48. <PartitionID>3</PartitionID>
  49. </InstallTo>
  50. </OSImage>
  51. </ImageInstall>
  52. <UserData>
  53. <ProductKey>
  54. <!-- Do not uncomment the Key element if you are using trial ISOs -->
  55. <!-- You must uncomment the Key element (and optionally insert your own key) if you are using retail or volume license ISOs -->
  56. <!-- <Key>6XBNX-4JQGW-QX6QG-74P76-72V67</Key> -->
  57. <WillShowUI>OnError</WillShowUI>
  58. </ProductKey>
  59. <AcceptEula>true</AcceptEula>
  60. <FullName>Vagrant</FullName>
  61. <Organization>Vagrant</Organization>
  62. </UserData>
  63. </component>
  64. </settings>
  65. <settings pass="specialize">
  66. <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
  67. <OEMInformation>
  68. <HelpCustomized>false</HelpCustomized>
  69. </OEMInformation>
  70. <ComputerName>vagrant-2016</ComputerName>
  71. <TimeZone>Pacific Standard Time</TimeZone>
  72. <RegisteredOwner/>
  73. </component>
  74. <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-ServerManager-SvrMgrNc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
  75. <DoNotOpenServerManagerAtLogon>true</DoNotOpenServerManagerAtLogon>
  76. </component>
  77. <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-IE-ESC" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
  78. <IEHardenAdmin>false</IEHardenAdmin>
  79. <IEHardenUser>false</IEHardenUser>
  80. </component>
  81. <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-OutOfBoxExperience" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
  82. <DoNotOpenInitialConfigurationTasksAtLogon>true</DoNotOpenInitialConfigurationTasksAtLogon>
  83. </component>
  84. <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Security-SPP-UX" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
  85. <SkipAutoActivation>true</SkipAutoActivation>
  86. </component>
  87. </settings>
  88. <settings pass="oobeSystem">
  89. <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
  90. <AutoLogon>
  91. <Password>
  92. <Value>vagrant</Value>
  93. <PlainText>true</PlainText>
  94. </Password>
  95. <Enabled>true</Enabled>
  96. <Username>vagrant</Username>
  97. </AutoLogon>
  98. <FirstLogonCommands>
  99. <SynchronousCommand wcm:action="add">
  100. <CommandLine>cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine>
  101. <Description>Set Execution Policy 64 Bit</Description>
  102. <Order>1</Order>
  103. <RequiresUserInput>true</RequiresUserInput>
  104. </SynchronousCommand>
  105. <SynchronousCommand wcm:action="add">
  106. <CommandLine>C:\Windows\SysWOW64\cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine>
  107. <Description>Set Execution Policy 32 Bit</Description>
  108. <Order>2</Order>
  109. <RequiresUserInput>true</RequiresUserInput>
  110. </SynchronousCommand>
  111. <SynchronousCommand wcm:action="add">
  112. <CommandLine>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File e:\disable-winrm.ps1</CommandLine>
  113. <Description>Disable WinRM</Description>
  114. <Order>3</Order>
  115. <RequiresUserInput>true</RequiresUserInput>
  116. </SynchronousCommand>
  117. <SynchronousCommand wcm:action="add">
  118. <CommandLine>%SystemRoot%\System32\reg.exe ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ /v HideFileExt /t REG_DWORD /d 0 /f</CommandLine>
  119. <Order>4</Order>
  120. <Description>Show file extensions in Explorer</Description>
  121. </SynchronousCommand>
  122. <SynchronousCommand wcm:action="add">
  123. <CommandLine>%SystemRoot%\System32\reg.exe ADD HKCU\Console /v QuickEdit /t REG_DWORD /d 1 /f</CommandLine>
  124. <Order>5</Order>
  125. <Description>Enable QuickEdit mode</Description>
  126. </SynchronousCommand>
  127. <SynchronousCommand wcm:action="add">
  128. <CommandLine>%SystemRoot%\System32\reg.exe ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ /v Start_ShowRun /t REG_DWORD /d 1 /f</CommandLine>
  129. <Order>6</Order>
  130. <Description>Show Run command in Start Menu</Description>
  131. </SynchronousCommand>
  132. <SynchronousCommand wcm:action="add">
  133. <CommandLine>%SystemRoot%\System32\reg.exe ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ /v StartMenuAdminTools /t REG_DWORD /d 1 /f</CommandLine>
  134. <Order>7</Order>
  135. <Description>Show Administrative Tools in Start Menu</Description>
  136. </SynchronousCommand>
  137. <SynchronousCommand wcm:action="add">
  138. <CommandLine>%SystemRoot%\System32\reg.exe ADD HKLM\SYSTEM\CurrentControlSet\Control\Power\ /v HibernateFileSizePercent /t REG_DWORD /d 0 /f</CommandLine>
  139. <Order>8</Order>
  140. <Description>Zero Hibernation File</Description>
  141. </SynchronousCommand>
  142. <SynchronousCommand wcm:action="add">
  143. <CommandLine>%SystemRoot%\System32\reg.exe ADD HKLM\SYSTEM\CurrentControlSet\Control\Power\ /v HibernateEnabled /t REG_DWORD /d 0 /f</CommandLine>
  144. <Order>9</Order>
  145. <Description>Disable Hibernation Mode</Description>
  146. </SynchronousCommand>
  147. <SynchronousCommand wcm:action="add">
  148. <CommandLine>cmd.exe /c wmic useraccount where "name='vagrant'" set PasswordExpires=FALSE</CommandLine>
  149. <Order>10</Order>
  150. <Description>Disable password expiration for vagrant user</Description>
  151. </SynchronousCommand>
  152. <SynchronousCommand wcm:action="add">
  153. <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File e:\enable-winrm.ps1</CommandLine>
  154. <Description>Enable WinRM</Description>
  155. <Order>99</Order>
  156. </SynchronousCommand>
  157. </FirstLogonCommands>
  158. <OOBE>
  159. <HideEULAPage>true</HideEULAPage>
  160. <HideLocalAccountScreen>true</HideLocalAccountScreen>
  161. <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>
  162. <HideOnlineAccountScreens>true</HideOnlineAccountScreens>
  163. <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
  164. <NetworkLocation>Home</NetworkLocation>
  165. <ProtectYourPC>1</ProtectYourPC>
  166. </OOBE>
  167. <UserAccounts>
  168. <AdministratorPassword>
  169. <Value>vagrant</Value>
  170. <PlainText>true</PlainText>
  171. </AdministratorPassword>
  172. <LocalAccounts>
  173. <LocalAccount wcm:action="add">
  174. <Password>
  175. <Value>vagrant</Value>
  176. <PlainText>true</PlainText>
  177. </Password>
  178. <Group>administrators</Group>
  179. <DisplayName>Vagrant</DisplayName>
  180. <Name>vagrant</Name>
  181. <Description>Vagrant User</Description>
  182. </LocalAccount>
  183. </LocalAccounts>
  184. </UserAccounts>
  185. <RegisteredOwner/>
  186. </component>
  187. </settings>
  188. <settings pass="offlineServicing">
  189. <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-LUA-Settings" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
  190. <EnableLUA>false</EnableLUA>
  191. </component>
  192. </settings>
  193. <cpi:offlineImage xmlns:cpi="urn:schemas-microsoft-com:cpi" cpi:source="wim:c:/wim/install.wim#Windows Server 2016 SERVERSTANDARD"/>
  194. </unattend>

从目录创建iso的PowerShell脚本

  1. function New-IsoFile
  2. {
  3. <# .Synopsis Creates a new .iso file .Description The New-IsoFile cmdlet creates a new .iso file containing content from chosen folders .Example New-IsoFile "c:\tools","c:Downloads\utils" This command creates a .iso file in $env:temp folder (default location) that contains c:\tools and c:\downloads\utils folders. The folders themselves are included at the root of the .iso image. .Example New-IsoFile -FromClipboard -Verbose Before running this command, select and copy (Ctrl-C) files/folders in Explorer first. .Example dir c:\WinPE | New-IsoFile -Path c:\temp\WinPE.iso -BootFile "${env:ProgramFiles(x86)}\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg\efisys.bin" -Media DVDPLUSR -Title "WinPE" This command creates a bootable .iso file containing the content from c:\WinPE folder, but the folder itself isn't included. Boot file etfsboot.com can be found in Windows ADK. Refer to IMAPI_MEDIA_PHYSICAL_TYPE enumeration for possible media types: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366217(v=vs.85).aspx .Notes NAME: New-IsoFile AUTHOR: Chris Wu LASTEDIT: 03/23/2016 14:46:50 #>
  4. [CmdletBinding(DefaultParameterSetName='Source')]Param(
  5. [parameter(Position=1,Mandatory=$true,ValueFromPipeline=$true, ParameterSetName='Source')]$Source,
  6. [parameter(Position=2)][string]$Path = "$env:temp\$((Get-Date).ToString('yyyyMMdd-HHmmss.ffff')).iso",
  7. [ValidateScript({Test-Path -LiteralPath $_ -PathType Leaf})][string]$BootFile = $null,
  8. [ValidateSet('CDR','CDRW','DVDRAM','DVDPLUSR','DVDPLUSRW','DVDPLUSR_DUALLAYER','DVDDASHR','DVDDASHRW','DVDDASHR_DUALLAYER','DISK','DVDPLUSRW_DUALLAYER','BDR','BDRE')][string] $Media = 'DVDPLUSRW_DUALLAYER',
  9. [string]$Title = (Get-Date).ToString("yyyyMMdd-HHmmss.ffff"),
  10. [switch]$Force,
  11. [parameter(ParameterSetName='Clipboard')][switch]$FromClipboard
  12. )
  13. Begin {
  14. ($cp = new-object System.CodeDom.Compiler.CompilerParameters).CompilerOptions = '/unsafe'
  15. if (!('ISOFile' -as [type])) {
  16. Add-Type -CompilerParameters $cp -TypeDefinition @'
  17. public class ISOFile
  18. {
  19. public unsafe static void Create(string Path, object Stream, int BlockSize, int TotalBlocks)
  20. {
  21. int bytes = 0;
  22. byte[] buf = new byte[BlockSize];
  23. var ptr = (System.IntPtr)(&bytes);
  24. var o = System.IO.File.OpenWrite(Path);
  25. var i = Stream as System.Runtime.InteropServices.ComTypes.IStream;
  26. if (o != null) {
  27. while (TotalBlocks-- > 0) {
  28. i.Read(buf, BlockSize, ptr); o.Write(buf, 0, bytes);
  29. }
  30. o.Flush(); o.Close();
  31. }
  32. }
  33. }
  34. '@
  35. }
  36. if ($BootFile) {
  37. if('BDR','BDRE' -contains $Media) { Write-Warning "Bootable image doesn't seem to work with media type $Media" }
  38. ($Stream = New-Object -ComObject ADODB.Stream -Property @{Type=1}).Open() # adFileTypeBinary
  39. $Stream.LoadFromFile((Get-Item -LiteralPath $BootFile).Fullname)
  40. ($Boot = New-Object -ComObject IMAPI2FS.BootOptions).AssignBootImage($Stream)
  41. }
  42. $MediaType = @('UNKNOWN','CDROM','CDR','CDRW','DVDROM','DVDRAM','DVDPLUSR','DVDPLUSRW','DVDPLUSR_DUALLAYER','DVDDASHR','DVDDASHRW','DVDDASHR_DUALLAYER','DISK','DVDPLUSRW_DUALLAYER','HDDVDROM','HDDVDR','HDDVDRAM','BDROM','BDR','BDRE')
  43. Write-Verbose -Message "Selected media type is $Media with value $($MediaType.IndexOf($Media))"
  44. ($Image = New-Object -com IMAPI2FS.MsftFileSystemImage -Property @{VolumeName=$Title}).ChooseImageDefaultsForMediaType($MediaType.IndexOf($Media))
  45. if (!($Target = New-Item -Path $Path -ItemType File -Force:$Force -ErrorAction SilentlyContinue)) { Write-Error -Message "Cannot create file $Path. Use -Force parameter to overwrite if the target file already exists."; break }
  46. }
  47. Process {
  48. if($FromClipboard) {
  49. if($PSVersionTable.PSVersion.Major -lt 5) { Write-Error -Message 'The -FromClipboard parameter is only supported on PowerShell v5 or higher'; break }
  50. $Source = Get-Clipboard -Format FileDropList
  51. }
  52. foreach($item in $Source) {
  53. if($item -isnot [System.IO.FileInfo] -and $item -isnot [System.IO.DirectoryInfo]) {
  54. $item = Get-Item -LiteralPath $item
  55. }
  56. if($item) {
  57. Write-Verbose -Message "Adding item to the target image: $($item.FullName)"
  58. try { $Image.Root.AddTree($item.FullName, $true) } catch { Write-Error -Message ($_.Exception.Message.Trim() + ' Try a different media type.') }
  59. }
  60. }
  61. }
  62. End {
  63. if ($Boot) { $Image.BootImageOptions=$Boot }
  64. $Result = $Image.CreateResultImage()
  65. [ISOFile]::Create($Target.FullName,$Result.ImageStream,$Result.BlockSize,$Result.TotalBlocks)
  66. Write-Verbose -Message "Target image ($($Target.FullName)) has been created"
  67. $Target
  68. }
  69. }
  70. $source_dir = "setup"
  71. get-childitem "$source_dir" | New-ISOFile -path setup.iso

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/934696
推荐阅读
相关标签
  

闽ICP备14008679号