47 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			PowerShell
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			PowerShell
		
	
	
	
	
	
#Requires -Modules 'GPWmiFilter'
 | 
						|
Param(
 | 
						|
    [Parameter(Mandatory)]
 | 
						|
    [hashtable]$Parameter
 | 
						|
)
 | 
						|
 | 
						|
# Only executed on primary or standalone Domain Controller
 | 
						|
If (@('primary','standalone') -contains $Parameter['deployment.type']) {
 | 
						|
    $GetContentSplat = @{
 | 
						|
        Path = "$($PSScriptRoot)\$($MyInvocation.MyCommand)".Replace('.ps1', '.yml')
 | 
						|
        Raw  = $True
 | 
						|
    }
 | 
						|
    $RawContent = Get-Content @GetContentSplat
 | 
						|
    $ConvertFromYamlSplat = @{
 | 
						|
        Yaml         = $RawContent
 | 
						|
        AllDocuments = $True
 | 
						|
    }
 | 
						|
    $YamlDocuments = ConvertFrom-Yaml @ConvertFromYamlSplat
 | 
						|
 | 
						|
    # Check if the respective .yml file declared substitutions which need to be parsed
 | 
						|
    If (($YamlDocuments.Count -gt 1) -and $YamlDocuments[-1].Variables) {
 | 
						|
        ForEach ($Pattern in $YamlDocuments[-1].Variables) {
 | 
						|
            $RawContent = $RawContent -replace "\{\{ ($($Pattern.Name)) \}\}", [string](Invoke-Expression -Command $Pattern.Expression)
 | 
						|
        }
 | 
						|
        # Perform conversion to Yaml again, now with parsed file contents
 | 
						|
        $ConvertFromYamlSplat = @{
 | 
						|
            Yaml         = $RawContent
 | 
						|
            AllDocuments = $True
 | 
						|
        }
 | 
						|
        $YamlDocuments = ConvertFrom-Yaml @ConvertFromYamlSplat
 | 
						|
        $WmiFilters = $YamlDocuments[0..($YamlDocuments.Count - 2)]
 | 
						|
    }
 | 
						|
    Else {
 | 
						|
        $WmiFilters = $YamlDocuments
 | 
						|
    }
 | 
						|
 | 
						|
    ForEach ($Filter in $WmiFilters) {
 | 
						|
        $NewGPWmiFilterSplat = @{
 | 
						|
            Name        = $Filter.Name
 | 
						|
            Description = $Filter.Description
 | 
						|
            Expression  = $Filter.Expressions
 | 
						|
            Server      = $Parameter['addsconfig.domainname']
 | 
						|
            ErrorAction = 'SilentlyContinue'
 | 
						|
        }
 | 
						|
        New-GPWmiFilter @NewGPWmiFilterSplat
 | 
						|
    }
 | 
						|
} |