Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Automating the installation of Windows operating systems can significantly reduce the time and effort required for deploying multiple machines. This article will guide you through the process of creating an unattended installation using Answer Files and automating post-installation tasks with PowerShell scripts.
An Answer File is an XML file used by Windows Setup to automate the installation process. It contains configuration settings and instructions that Windows Setup uses to install and configure the OS without user intervention.
Microsoft-Windows-Setup
component and configure the DiskConfiguration
settings.autounattend.xml
.<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="windowsPE">
<component name="Microsoft-Windows-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
<DiskConfiguration>
<Disk wcm:action="add">
<DiskID>0</DiskID>
<WillWipeDisk>true</WillWipeDisk>
<CreatePartitions>
<CreatePartition wcm:action="add">
<Order>1</Order>
<Type>Primary</Type>
<Size>100000</Size>
</CreatePartition>
<CreatePartition wcm:action="add">
<Order>2</Order>
<Type>Primary</Type>
<Extend>true</Extend>
</CreatePartition>
</CreatePartitions>
<ModifyPartitions>
<ModifyPartition wcm:action="add">
<Active>true</Active>
<Format>NTFS</Format>
<Label>System</Label>
<Order>1</Order>
<PartitionID>1</PartitionID>
</ModifyPartition>
<ModifyPartition wcm:action="add">
<Active>false</Active>
<Format>NTFS</Format>
<Label>Windows</Label>
<Order>2</Order>
<PartitionID>2</PartitionID>
</ModifyPartition>
</ModifyPartitions>
</Disk>
</DiskConfiguration>
</component>
</settings>
</unattend>
After the OS is installed, you can use PowerShell scripts to automate additional configuration tasks.
Create a PowerShell script named PostInstall.ps1
:
# Set the computer name
Rename-Computer -NewName "NewComputerName" -Force -Restart
# Install Windows Features
Install-WindowsFeature -Name Web-Server, Web-Mgmt-Tools
# Create a new user
New-LocalUser -Name "NewUser" -Password (ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force) -FullName "New User" -Description "A new local user"
# Add the user to the Administrators group
Add-LocalGroupMember -Group "Administrators" -Member "NewUser"
To execute this script automatically after installation, you can add it to the FirstLogonCommands
section of your Answer File:
<FirstLogonCommands>
<SynchronousCommand wcm:action="add">
<CommandLine>powershell.exe -ExecutionPolicy Bypass -File C:\Scripts\PostInstall.ps1</CommandLine>
<Description>Run Post-Installation Script</Description>
<Order>1</Order>
</SynchronousCommand>
</FirstLogonCommands>
By following these steps, you can create an automated Windows installation process that includes both the initial OS setup and post-installation configuration. This can save significant time and ensure consistency across multiple deployments.