In relation to this question that was answered, we now have an issue where some values are arrays and we need to retain that structure
The code as it stands is:
function Get-Node {
[CmdletBinding()][OutputType([Object[]])] param(
[ScriptBlock]$Where,
[AllowNull()]
[Parameter(ValueFromPipeLine = $True, Mandatory = $True)]$InputObject,
[Int]$Depth = 90
)
process {
if ($_ -isnot [String] -and $Depth -gt 0) {
if ($_ -is [Collections.IDictionary]) {
if (& $Where) { $_ }
$_.get_Values() | Get-Node -Where $Where -Depth ($Depth - 1)
}
elseif ($_ -is [Collections.IEnumerable]) {
for ($i = 0; $i -lt $_.get_Count(); $i++) {
$_[$i] | Get-Node -Where $Where -Depth ($Depth - 1)
}
}
elseif ($Nodes = $_.PSObject.Properties.Where{ $_.MemberType -eq 'NoteProperty' }) {
$Nodes.ForEach{
if (& $Where) { $_ }
$_.Value | Get-Node -Where $Where -Depth ($Depth - 1)
Write-Host "In Second If " $_.Value
Write-Host "In Second If 2" $_
}
}
}
}
}
And the above function is called via:
if ($content.properties.policyRule -ne $null){
foreach ($rule in $policyRule){
$Node = $content.properties | Get-Node -Where {$_.name -eq $rule -and $_.value -Match "^\[\w+"}
$Node | ForEach-Object {
$_.Value = '[' + $_.Value
}
}
}
And what we are seeing is this:
"notIn": "[[concat(subscription().id,'/')] [subscription().id] /"
What we ideally want:
"notIn": ["[[concat(subscription().id,'/')]", "[[subscription().id]", "/"]
Any suggestions would be grateful