Skip to content

Instantly share code, notes, and snippets.

@SightSpirit
Created June 5, 2023 13:48
Show Gist options
  • Save SightSpirit/9c77a1c000888f2c1e9b454f6d95ed4b to your computer and use it in GitHub Desktop.
Save SightSpirit/9c77a1c000888f2c1e9b454f6d95ed4b to your computer and use it in GitHub Desktop.
Windows PowerShell script to import Group Policy templates from Desktop
#Requires -RunAsAdministrator
function Pop() { Pop-Location }
"$env:USERPROFILE\Desktop" | Push-Location
"Looking for ADMX files..."
$admx = Get-Item *.admx -ErrorAction SilentlyContinue
if ($admx.Count -lt 1) {
Write-Error "Unable to find any ADMX files on the Desktop."
} else {
"Attempting to import ADMX files into templates..."
try {
$admx | ForEach-Object { Move-Item $_ -Destination "$env:windir\PolicyDefinitions" }
"Success! ADMX files imported."
} catch {
Write-Error "Something went wrong. Unable to import one or more ADMX file(s)."
}
}
# IF USING LOCALE OTHER THAN en-US, MAKE APPROPRIATE CHANGES ON LINES 22, 25, AND 29.
"Looking for template strings..."
$enus = Get-Item .\en-US -ErrorAction SilentlyContinue
if (!($enus.Exists) -or !($enus.Mode.StartsWith("d"))) {
Pop
throw 'Unable to find the "en-US" folder on the Desktop.'
} else {
"Attempting to import template strings..."
try {
$enus | Get-ChildItem -Recurse -File | ForEach-Object { Move-Item $_.FullName -Destination "$env:windir\PolicyDefinitions\en-US" }
"Success! All string files imported."
} catch {
Pop
throw "Something went wrong. Unable to import one or more string files."
}
}
$enus | Remove-Item
"Cleaned up! Thank you so much for playing my game!"
Pause
Pop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment