Windows 10, Windows Server

Automate Administrative Templates to Central Store



INTRO

If you’re a Sysadmin like I then you know how powerful Microsoft’s Group Policy Management features are in a Windows Server environment where Active Directory is implemented. It’s important then that we keep these policies updated to resolve issues with them.

OFFICIAL DOCUMENTATION

Microsoft has official documentation here on how to perform the process manually on your Windows Domain Controllers or PDCs. You can download the latest templates there, but also keep in-mind other third-party applications have templates as well you can apply, for example Google Chrome, Mozilla Firefox to name a couple. These templates are very handy in controlling your environments.

AUTOMATE INSTALL SCRIPT | POWERSHELL

After installing them a few times and getting tired of it I made a PowerShell script to automate the process. Please let me know if you have issues as I kind of edited this one on the fly for this post without testing but the core of it has been tested. I made sure not to overwrite your current templates.

PowerShell
# Define the URL of the file to download.
$URL = "https://download.microsoft.com/download/8/e/1/8e1c2d4e-9126-4096-8b84-36aa9f524b47/Administrative%20Templates%20(.admx)%20for%20Windows%2011%20July%202023%20Update%20V3.msi"

# Make directory.
New-Item -Path 'C:\TEMP' -ItemType Directory -Force -WarningAction SilentlyContinue -ErrorAction SilentlyContinue | Out-Null

# Define the destination folder to extract to.
$Destination = "C:\TEMP"

# Download the file from the URL.
$DownloadPath = Join-Path $Destination "Administrative_Templates_for_Windows_11_July_2023_Update_V3.msi"
Invoke-WebRequest -Uri $URL -OutFile $DownloadPath

# Install the file from the URL.
Start-Process "Administrative_Templates_for_Windows_11_July_2023_Update_V3.msi" -WorkingDirectory "C:\TEMP" -ArgumentList "/Quiet" -PassThru

# Copy policy templates to SYSVOL location.
Copy-Item -Path "C:\Program Files (x86)\Microsoft Group Policy\Windows 11 July 2023 Update V3 (22H2)\PolicyDefinitions" -Destination "C:\Windows\SYSVOL\domain\Policies\PolicyDefinitions_Win11-22H2-v3" -Recurse -Force

# Check for copied folder then rename and apply.
$Folder = 'C:\Windows\SYSVOL\domain\Policies\PolicyDefinitions_Win11-22H2-v3'
"Test to see if folder [$Folder] exists"
if (Test-Path -Path $Folder) {
    Rename-Item -Path "C:\Windows\SYSVOL\domain\Policies\PolicyDefinitions" -NewName "PolicyDefinitions_old" -Force
    Rename-Item -path "C:\Windows\SYSVOL\domain\Policies\PolicyDefinitions_Win11-22H2-v3" -NewName "PolicyDefinitions" -Force
    GPUpdate /Force
} else {
    "An error has occured."
}

# Cleanup
Remove-Item -Path "C:\TEMP\Administrative_Templates_for_Windows_11_July_2023_Update_V3.msi" -Force

CONCLUSION

Well, that’s about it, hope this saves you some time.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *