Add new ADMX template handling functions and example script

This commit is contained in:
Przemyslaw Klys
2024-12-02 22:35:29 +01:00
parent cd72f79f85
commit 170896c0cc
4 changed files with 110 additions and 2 deletions
+17
View File
@@ -0,0 +1,17 @@
function Get-GPOZaurrTemplates {
[CmdletBinding()]
param(
)
$SysvolADMXPath = "\\$env:USERDNSDOMAIN\SYSVOL\$env:USERDNSDOMAIN\Policies\PolicyDefinitions"
Get-ChildItem -Path $SysvolADMXPath -Filter "*.admx" -Recurse -File | ForEach-Object {
[PSCustomObject]@{
Name = $_.Name
Path = $_.FullName
Size = $_.Length
LastWriteTime = $_.LastWriteTime
}
}
}
+72
View File
@@ -0,0 +1,72 @@
function Initialize-GPOZaurrTemplate {
[CmdletBinding()]
param(
[Parameter(Mandatory)][string] $Name,
[Parameter(Mandatory)][string] $Path,
[string] $ExportPath
)
$Files = Get-ChildItem -Path $Path -Filter "*.admx" -Recurse -File
$TotalFiles = $Files.Count
$ProgressIncrement = [math]::Ceiling($TotalFiles / 10)
$CurrentProgress = 0
$FullList = foreach ($File in $Files) {
$CurrentProgress++
if ($CurrentProgress % $ProgressIncrement -eq 0) {
Write-Verbose ("Initialize-GPOZaurrTemplate - Processing $Name, template file {0} of {1} ({2}%)" -f $CurrentProgress, $TotalFiles, [math]::Round(($CurrentProgress / $TotalFiles) * 100))
}
$HashInformation = Get-FileHash -LiteralPath $File.FullName
$Directories = Get-ChildItem -Path $File.DirectoryName -Directory
$Languages = [ordered] @{}
foreach ($Directory in $Directories) {
$LanguageFile = [io.path]::Combine($Directory.FullName, $File.BaseName + ".adml")
$Item = Get-Item -Path $LanguageFile -ErrorAction SilentlyContinue
if (Test-Path -Path $LanguageFile) {
$HashInformation = Get-FileHash -LiteralPath $LanguageFile
$Languages[$Directory.Name] = [PSCustomObject]@{
Name = $Directory.Name
Hash = $HashInformation.Hash
Algorithm = $HashInformation.Algorithm
Size = $Item.Length
CreationTimeUtc = $Item.CreationTimeUtc
LastWriteTimeUtc = $Item.LastWriteTimeUtc
}
}
}
[PSCustomObject] @{
Name = $File.Name
Hash = $HashInformation.Hash
Algorithm = $HashInformation.Algorithm
Size = $File.Length
LanguagesAvailable = $Languages.Keys
LanguagesCount = $Languages.Keys.Count
CreationTimeUtc = $File.CreationTimeUtc
LastWriteTimeUtc = $File.LastWriteTimeUtc
LanguageFile = $Languages
}
}
$OutputObject = [PSCustomObject] @{
Name = $Name
Path = $Path
Templates = $FullList
}
if ($ExportPath) {
if ($ExportPath.EndsWith('.xml')) {
$ExportType = 'XML'
} elseif ($ExportPath.EndsWith('.json')) {
$ExportType = 'JSON'
} else {
$ExportType = 'XML'
}
if ($ExportType -eq 'XML') {
$OutputObject | Export-Clixml -Path $ExportPath -ErrorAction Stop
} elseif ($ExportType -eq 'JSON') {
$OutputObject | ConvertTo-Json -Depth 10 | Set-Content -Path $ExportPath -ErrorAction Stop
} else {
Write-Warning "ExportType $ExportType is not supported. Exporting to XML."
}
}
$OutputObject
}