Skip to content

Instantly share code, notes, and snippets.

@DrJZoidberg
Created August 23, 2020 13:57
Show Gist options
  • Save DrJZoidberg/0f749591b9f6a2668d6e5eaa62372b29 to your computer and use it in GitHub Desktop.
Save DrJZoidberg/0f749591b9f6a2668d6e5eaa62372b29 to your computer and use it in GitHub Desktop.
Autounattend_proto
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="windowsPE">
<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-US</UILanguage>
<WillShowUI>Never</WillShowUI>
</SetupUILanguage>
<InputLocale>en-US</InputLocale>
<SystemLocale>en-US</SystemLocale>
<UILanguage>en-US</UILanguage>
<UserLocale> en-US</UserLocale>
</component>
<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">
<UserData>
<AcceptEula>true</AcceptEula>
<ProductKey>
<Key>VK7JG-NPHTM-C97JM-9MPGT-3V66T</Key>
</ProductKey>
</UserData>
<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>Primary</Type>
<Extend>true</Extend>
</CreatePartition>
</CreatePartitions>
<ModifyPartitions>
<ModifyPartition wcm:action="add">
<Format>NTFS</Format>
<Label>System</Label>
<Order>1</Order>
<PartitionID>1</PartitionID>
<Active>true</Active>
</ModifyPartition>
<ModifyPartition wcm:action="add">
<Format>NTFS</Format>
<Label>Windows</Label>
<Order>2</Order>
<PartitionID>2</PartitionID>
<Letter>C</Letter>
</ModifyPartition>
</ModifyPartitions>
<WillWipeDisk>true</WillWipeDisk>
<DiskID>0</DiskID>
</Disk>
</DiskConfiguration>
<ImageInstall>
<OSImage>
<InstallFrom>
<MetaData wcm:action="add">
<Key>/IMAGE/INDEX</Key>
<Value>6</Value>
</MetaData>
</InstallFrom>
<InstallToAvailablePartition>true</InstallToAvailablePartition>
</OSImage>
</ImageInstall>
</component>
</settings>
<settings pass="specialize">
<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">
<ComputerName>Win10Commando</ComputerName>
<RegisteredOrganization>planetExpress</RegisteredOrganization>
<RegisteredOwner>packerCommando</RegisteredOwner>
<TimeZone>Eastern Standard Time</TimeZone>
</component>
<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">
<SkipAutoActivation>true</SkipAutoActivation>
</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-US</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" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<OOBE>
<HideEULAPage>true</HideEULAPage>
<HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>
<HideOnlineAccountScreens>true</HideOnlineAccountScreens>
<HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
<NetworkLocation>Work</NetworkLocation>
<ProtectYourPC>3</ProtectYourPC>
</OOBE>
<UserAccounts>
<LocalAccounts>
<LocalAccount wcm:action="add">
<Password>
<Value>packer-commando</Value>
<PlainText>true</PlainText>
</Password>
<Description>Primary local account</Description>
<DisplayName>packer-commando</DisplayName>
<Group>Administrators</Group>
<Name>packer-commando</Name>
</LocalAccount>
</LocalAccounts>
</UserAccounts>
<WindowsFeatures>
<ShowInternetExplorer>true</ShowInternetExplorer>
</WindowsFeatures>
<AutoLogon>
<Password>
<Value>packer-commando</Value>
<PlainText>true</PlainText>
</Password>
<Enabled>true</Enabled>
<LogonCount>999</LogonCount>
<Username>packer-commando</Username>
</AutoLogon>
<FirstLogonCommands>
<SynchronousCommand wcm:action="add">
<CommandLine>powershell -ExecutionPolicy Bypass -File a:\setup.ps1</CommandLine>
<Description>Enable WinRM service</Description>
<Order>1</Order>
<RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<Description>Control Panel View</Description>
<Order>2</Order>
<CommandLine>reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel" /v StartupPage /t REG_DWORD /d 1 /f</CommandLine>
<RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<Order>3</Order>
<Description>Control Panel Icon Size</Description>
<RequiresUserInput>false</RequiresUserInput>
<CommandLine>reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel" /v AllItemsIconView /t REG_DWORD /d 0 /f</CommandLine>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<Order>4</Order>
<RequiresUserInput>false</RequiresUserInput>
<CommandLine>cmd /C wmic useraccount where name="packer-commando" set PasswordExpires=false</CommandLine>
<Description>Password Never Expires</Description>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<CommandLine>cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine>
<Description>Set Execution Policy 64 Bit</Description>
<Order>5</Order>
<RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<Description>Disable Windows Defender key 1</Description>
<Order>6</Order>
<CommandLine>reg add "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows Defender" /v DisableAntiSpyware /t REG_DWORD /d 1 /f</CommandLine>
<RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<Description>Disable Windows Defender key 2</Description>
<Order>7</Order>
<CommandLine>reg add "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows Defender" /v DisableRealtimeMonitoring /t REG_DWORD /d 1 /f</CommandLine>
<RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<Description>Disable Windows Defender key 3</Description>
<Order>8</Order>
<CommandLine>reg add "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows Defender\Real-Time Protection" /v DisableBehaviorMonitoring /t REG_DWORD /d 1 /f</CommandLine>
<RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<Description>Disable Windows Defender key 4</Description>
<Order>9</Order>
<CommandLine>reg add "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows Defender\Real-Time Protection" /v DisableOnAccessProtection /t REG_DWORD /d 1 /f</CommandLine>
<RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<Description>Disable Windows Defender key 5</Description>
<Order>10</Order>
<CommandLine>reg add "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows Defender\Real-Time Protection" /v DisableScanOnRealtimeEnable /t REG_DWORD /d 1 /f</CommandLine>
<RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
</FirstLogonCommands>
</component>
</settings>
<settings pass="offlineServicing">
<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">
<EnableLUA>false</EnableLUA>
</component>
</settings>
</unattend>
$ErrorActionPreference = "Stop"
# Switch network connection to private mode
# Required for WinRM firewall rules
$profile = Get-NetConnectionProfile
Set-NetConnectionProfile -Name $profile.Name -NetworkCategory Private
# Enable WinRM service
winrm quickconfig -quiet
winrm set winrm/config/client/auth '@{Basic="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="2048"}'
Restart-Service -Name WinRM
netsh advfirewall firewall add rule name="WinRM-HTTP" dir=in localport=5985 protocol=TCP action=allow
netsh advfirewall firewall add rule name="WinRM-HTTPS" dir=in localport=5986 protocol=TCP action=allow
# Reset auto logon count
# https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-shell-setup-autologon-logoncount#logoncount-known-issue
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoLogonCount -Value 999
# Change some standard windows explorer settings that suck
$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced'
Set-ItemProperty $key Hidden 1
Set-ItemProperty $key HideFileExt 0
Set-ItemProperty $key ShowSuperHidden 1
# Reboot of explorer needed for these to take effect
Stop-Process -processname explorer
Start-Process -processname explorer
# Set password to never expire (Using wmic since the latest version of powershell is the only one that works with Set-LocalUser
wmic useraccount WHERE "Name='$Env:Username'" SET PasswordExpires=false
# Set the execution policy of the powershell prompt
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
# Room for further changes here. These should be in the interests of creating templates which are going to be customized by Ansible, not specific actions
$registryPath = "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\WinLogon"
$Name = "DefaultUserName"
$NameValue = "packer-commando"
$Password = "DefaultPassword"
$PasswordValue = "packer-commando"
$AutoName = "AutoAdminLogon"
New-ItemProperty -Path $registryPath -Name $Name -Value $NameValue -PropertyType "String" -Force | Out-Null
New-ItemProperty -Path $registryPath -Name $Password -Value $PasswordValue -PropertyType "String" -Force | Out-Null
New-ItemProperty -Path $registryPath -Name $AutoName -Value "1" -PropertyType "String" -Force | Out-Null
{
"_comment_space": "",
"builders": [
{
"type": "virtualbox-vm",
"vm_name": "Windows_10_2004_x64_commando",
"communicator": "winrm",
"winrm_username": "packer-commando",
"winrm_password": "packer-commando",
"disable_shutdown": true,
"keep_registered": true,
"target_snapshot": "commando-snapshot",
"attach_snapshot": "Snapshot_1",
"force_delete_snapshot": true,
"skip_export": true,
"shutdown_timeout": "30m"
}
],
"provisioners": [
{
"type": "windows-shell",
"inline": ["dir c:\\"]
},
{
"type": "file",
"source": "install.ps1",
"destination": "C:/Users/packer-commando/Downloads/install.ps1"
},
{
"type": "file",
"source": "lite.json",
"destination": "C:/Users/packer-commando/Downloads/lite.json"
},
{
"pause_before": "30s",
"type": "powershell",
"inline": [
"Unblock-File C:/Users/packer-commando/Downloads/install.ps1",
"C:/Users/packer-commando/Downloads/install.ps1 -password packer-commando -snapshot_check 0"
]
},
{
"pause_before": "60m",
"max_retries": 10,
"type": "windows-shell",
"inline": ["dir c:\\"]
}
]
}
{
"_comment_space": "",
"builders": [
{
"type": "virtualbox-iso",
"vm_name": "Windows_10_2004_x64_commando",
"guest_os_type": "Windows10_64",
"iso_url": "http://0.0.0.0:8080/Win10_2004_English_x64.iso",
"iso_checksum": "md5:3cf9848ce17271e7c895366bdad98a8e",
"communicator": "winrm",
"winrm_username": "packer-commando",
"winrm_password": "packer-commando",
"cpus": "4",
"memory": "4096",
"disk_size": "71680",
"hard_drive_interface": "sata",
"floppy_files": [
"<location>/floppy/Autounattend.xml",
"<location>/floppy/setup.ps1"
],
"shutdown_command": "shutdown /s /t 0",
"keep_registered": true,
"hard_drive_nonrotational": true
}
],
"provisioners": [
{
"type": "windows-shell",
"inline": ["dir c:\\"]
},
{
"pause_before": "10m",
"type": "windows-update",
"search_criteria": "IsInstalled=0",
"filters": [
"exclude:$_.Title -like '*Preview*'",
"include:$true"
]
}
]
}
@awsvpc
Copy link

awsvpc commented Dec 25, 2023

unattend1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment