Fix switch regex match;Add GPO link debugging
This commit is contained in:
parent
a0956209de
commit
b02dcfa717
@ -15,13 +15,15 @@ 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 '$($_)' ..."
|
||||
ForEach ($File in (Get-Item @GetItemSplat)) {
|
||||
Try {
|
||||
Write-Host "Loading/parsing file '$($File)' ..."
|
||||
$GetContentSplat = @{
|
||||
Path = $_
|
||||
Path = $File
|
||||
Raw = $True
|
||||
}
|
||||
$RawContent = Get-Content @GetContentSplat
|
||||
@ -30,9 +32,15 @@ If (@('primary','standalone') -contains $Parameter['deployment.type']) {
|
||||
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)
|
||||
}
|
||||
@ -42,6 +50,12 @@ If (@('primary','standalone') -contains $Parameter['deployment.type']) {
|
||||
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")"
|
||||
}
|
||||
}
|
||||
|
@ -128,13 +128,13 @@ ForEach ($Category in $OVFConfig.PropertyCategories) {
|
||||
$XMLPropertyAttrKey.Value = $Property.Key
|
||||
$XMLPropertyAttrType = $XML.CreateAttribute('type', $XML.DocumentElement.ovf)
|
||||
Switch -regex ($Property.Type) {
|
||||
'boolean' {
|
||||
'^boolean' {
|
||||
$XMLPropertyAttrType.Value = 'boolean'
|
||||
}
|
||||
'int' {
|
||||
'^int' {
|
||||
$XMLPropertyAttrType.Value = 'uint8'
|
||||
$Qualifiers = @()
|
||||
If ($Property.Type -match 'int\((\d*)\.\.(\d*)\)') {
|
||||
If ($Property.Type -match '^int\((\d*)\.\.(\d*)\)') {
|
||||
If ($Matches[1]) {
|
||||
$Qualifiers += "MinValue($($Matches[1]))"
|
||||
}
|
||||
@ -146,20 +146,20 @@ ForEach ($Category in $OVFConfig.PropertyCategories) {
|
||||
[void]$XMLProperty.Attributes.Append($XMLPropertyAttrQualifiers)
|
||||
}
|
||||
}
|
||||
'ip' {
|
||||
'^ip' {
|
||||
$XMLPropertyAttrType.Value = 'string'
|
||||
$XMLPropertyAttrQualifiers = $XML.CreateAttribute('qualifiers', $XML.DocumentElement.vmw)
|
||||
$XMLPropertyAttrQualifiers.Value = 'Ip'
|
||||
[void]$XMLProperty.Attributes.Append($XMLPropertyAttrQualifiers)
|
||||
}
|
||||
'password' {
|
||||
'^password' {
|
||||
$XMLPropertyAttrType.Value = 'string'
|
||||
$XMLPropertyAttrPassword = $XML.CreateAttribute('password', $XML.DocumentElement.ovf)
|
||||
$XMLPropertyAttrPassword.Value = 'true'
|
||||
[void]$XMLProperty.Attributes.Append($XMLPropertyAttrPassword)
|
||||
|
||||
$Qualifiers = @()
|
||||
If ($Property.Type -match 'password\((\d*)\.\.(\d*)\)') {
|
||||
If ($Property.Type -match '^password\((\d*)\.\.(\d*)\)') {
|
||||
If ($Matches[1]) {
|
||||
$Qualifiers += "MinLen($($Matches[1]))"
|
||||
}
|
||||
@ -171,10 +171,10 @@ ForEach ($Category in $OVFConfig.PropertyCategories) {
|
||||
[void]$XMLProperty.Attributes.Append($XMLPropertyAttrQualifiers)
|
||||
}
|
||||
}
|
||||
'string' {
|
||||
'^string' {
|
||||
$XMLPropertyAttrType.Value = 'string'
|
||||
$Qualifiers = @()
|
||||
If ($Property.Type -match 'string\((\d*)\.\.(\d*)\)') {
|
||||
If ($Property.Type -match '^string\((\d*)\.\.(\d*)\)') {
|
||||
If ($Matches[1]) {
|
||||
$Qualifiers += "MinLen($($Matches[1]))"
|
||||
}
|
||||
@ -184,7 +184,7 @@ ForEach ($Category in $OVFConfig.PropertyCategories) {
|
||||
$XMLPropertyAttrQualifiers = $XML.CreateAttribute('qualifiers', $XML.DocumentElement.ovf)
|
||||
$XMLPropertyAttrQualifiers.Value = $Qualifiers -join ' '
|
||||
[void]$XMLProperty.Attributes.Append($XMLPropertyAttrQualifiers)
|
||||
} ElseIf ($Property.Type -match 'string\[(.*)\]') {
|
||||
} ElseIf ($Property.Type -match '^string\[(.*)\]') {
|
||||
$XMLPropertyAttrQualifiers = $XML.CreateAttribute('qualifiers', $XML.DocumentElement.ovf)
|
||||
$XMLPropertyAttrQualifiers.Value = "ValueMap{$($Matches[1] -replace '","', '", "')}"
|
||||
[void]$XMLProperty.Attributes.Append($XMLPropertyAttrQualifiers)
|
||||
|
Loading…
Reference in New Issue
Block a user