Fix switch regex match;Add GPO link debugging
This commit is contained in:
		| @@ -15,33 +15,47 @@ If (@('primary','standalone') -contains $Parameter['deployment.type']) { | ||||
|     } | ||||
|     $PSSession = New-PSSession @NewPSSessionSplat | ||||
|  | ||||
|     $ParseErrors = @() | ||||
|     $GetItemSplat = @{ | ||||
|         Path = "$($PSScriptRoot)\$($MyInvocation.MyCommand)".Replace('.ps1', '.*.yml') | ||||
|     } | ||||
|     Get-Item @GetItemSplat | ForEach-Object { | ||||
|         Write-Host "Loading/parsing file '$($_)' ..." | ||||
|         $GetContentSplat = @{ | ||||
|             Path = $_ | ||||
|             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) | ||||
|     ForEach ($File in (Get-Item @GetItemSplat)) { | ||||
|         Try { | ||||
|             Write-Host "Loading/parsing file '$($File)' ..." | ||||
|             $GetContentSplat = @{ | ||||
|                 Path = $File | ||||
|                 Raw  = $True | ||||
|             } | ||||
|             # Perform conversion to Yaml again, now with parsed file contents | ||||
|             $RawContent = Get-Content @GetContentSplat | ||||
|             $ConvertFromYamlSplat = @{ | ||||
|                 Yaml         = $RawContent | ||||
|                 AllDocuments = $True | ||||
|             } | ||||
|             $YamlDocuments = ConvertFrom-Yaml @ConvertFromYamlSplat | ||||
|         } | ||||
|         Catch { | ||||
|             $ParseErrors += "While processing '$($File)': $($_.Exception.Message)" | ||||
|             Continue | ||||
|         } | ||||
|  | ||||
|         # Check if the respective .yml file declared substitutions which need to be parsed | ||||
|         If (($YamlDocuments.Count -gt 1) -and $YamlDocuments[-1].Variables) { | ||||
|             Try { | ||||
|                 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 | ||||
|             } | ||||
|             Catch { | ||||
|                 $ParseErrors += "While processing '$($File)' (after substitutions): $($_.Exception.Message)" | ||||
|                 Continue | ||||
|             } | ||||
|  | ||||
|             $GroupPolicies = $YamlDocuments[0..($YamlDocuments.Count - 2)] | ||||
|         } | ||||
|         Else { | ||||
| @@ -160,19 +174,22 @@ If (@('primary','standalone') -contains $Parameter['deployment.type']) { | ||||
|             } | ||||
|  | ||||
|             ForEach ($OU in $GroupPolicy.LinkedOUs) { | ||||
|                 If (Test-Path "AD:\$($OU + ',DC=' + $Parameter['addsconfig.domainname'].Replace('.', ',DC='))") { | ||||
|                 If (Test-Path "AD:\$($OU + (',{0}' -f (Get-ADRootDSE).rootDomainNamingContext))") { | ||||
|                     Write-Host "Linking policy '$($NewGPO.DisplayName)' to OU '$($OU)' ..." | ||||
|                     $NewGPLinkSplat = @{ | ||||
|                         Name        = $NewGPO.DisplayName | ||||
|                         Target      = $OU + ',DC=' + $Parameter['addsconfig.domainname'].Replace('.', ',DC=') | ||||
|                         Target      = $OU + (',{0}' -f (Get-ADRootDSE).rootDomainNamingContext) | ||||
| #                        ErrorAction = 'SilentlyContinue' | ||||
|                     } | ||||
|                     New-GPLink @NewGPLinkSplat | Out-Null | ||||
|                 } | ||||
|                 Else { | ||||
|                     Throw "Path not accessible: 'AD:\$($OU + ',DC=' + $Parameter['addsconfig.domainname'].Replace('.', ',DC='))'" | ||||
|                     Throw "Path not accessible: 'AD:\$($OU + (',{0}' -f (Get-ADRootDSE).rootDomainNamingContext))" | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     If ($ParseErrors) { | ||||
|         Throw "One or more errors occurred:`n$($ParseErrors -join "`n")" | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user