In powershell I've got a COM object which has several child COM objects which themselves have child com objects. I want to be able to get the top level object if the child of the child has a particular property. Unfortunately many of the objects don't have names and the structure doesn't make much sense to me.
I can get there potentially with a loop but I'd rather avoid that if I can.
When I put this into powershell
$jobobj.steps
I get the following output:
Name :
Value : System.__ComObject
Description :
AccessType : 0
ExportAsEnvironmentVariable : False
ReadOnly : False
Use : 1
Volatile : False
Secured : False
Options :
Name : JobStepComment
Value :
Description :
AccessType : 0
ExportAsEnvironmentVariable : False
ReadOnly : False
Use : 1
Volatile : False
Secured : False
Options :
Then I put in
$jobobj.Steps[1].value
Which returns a bunch of properties as objects like above. I won't provide the full list as it would fill the page but here is a small subset.
Name : Values
Value : System.__ComObject
Description :
AccessType : 0
ExportAsEnvironmentVariable : False
ReadOnly : False
Use : 1
Volatile : False
Secured : False
Options :
Name : Bindings
Value : System.__ComObject
Description :
AccessType : 0
ExportAsEnvironmentVariable : False
ReadOnly : False
Use : 1
Volatile : False
Secured : False
Options :
The below steps get me to what I want but I'm very much assuming I'm picking up the right object in the array by hardcoding the [1] and [2].
Is there any way to filter the $jobobj.Steps Value based on the properties of sub object of sub objects so I don't have to assume I'm choosing the right number in the array?
$Bindings = $jobobj.Steps[1].value | Where-Object {$_.Name -eq "bindings"}
$Items = $Bindings.value | where-object {$_.Name -eq "Items"}
$Config = ($items.value[2]).value | where-object {$_.Name -eq "Value" -and $_.Value -EQ '${CONNECTIONSTRING_CORE}'}