Hi,
I am attempting to loop through all the controls used in PS via a WPF form. At this point I am just trying to get all the controls recognised but it it does not seem to be seeing all the children
I have a stackpanel - WPF code here - not the complete code of the project
<StackPanel x:Name=“spBasicDRVSTART” Grid.Row=“0” Orientation=“Horizontal” >
<Label x:Name=“lblPullService” Grid.Row=“0” Margin=“3”>
<CheckBox x:Name=“chkPullService” Content=“Pull Service” VerticalContentAlignment=“Center” />
</Label>
<Label x:Name=“lblAudit” Grid.Row=“0” Margin=“3”>
<CheckBox x:Name=“chkAudit” Content=“Audit” VerticalContentAlignment=“Center” />
</Label>
<Grid x:Name=“grdAuditHostname” Visibility=“Collapsed” Width=“167” Margin=“3,0”>
<Grid.RowDefinitions>
<RowDefinition Height=“25.6”/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Content=“Audit Hostname” Height=“26” Grid.RowSpan=“2” VerticalAlignment=“Top” HorizontalAlignment=“Left” Margin=“3” />
<TextBox Grid.Row=“1” Name=“AuditHostname” BorderBrush=“Black” />
</Grid>
<Grid x:Name=“grdAuditInterval” Visibility=“Collapsed” Width=“167” Margin=“3,0”>
<Grid.RowDefinitions>
<RowDefinition Height=“25.6”/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Content=“Audit Interval (Hours)” Height=“26” Grid.RowSpan=“2” VerticalAlignment=“Top” HorizontalAlignment=“Left” Margin=“3” />
<TextBox Grid.Row=“1” Name=“AuditInterval” BorderBrush=“Black” HorizontalAlignment=“Center” />
</Grid>
<Label x:Name=“lblDirectSecureRelease”>
<CheckBox Content=“Direct Secure Release” VerticalContentAlignment=“Center” Margin=“3”/>
</Label>
<Label x:Name=“lblPrintPolicy” >
<CheckBox Content=“Print Policy” VerticalContentAlignment=“Center” Margin=“3”/>
</Label>
<Label x:Name=“lblUpdate” >
<CheckBox x:Name=“chkUpdate” Content=“Update” VerticalContentAlignment=“Center” Margin=“3” />
</Label>
<Grid x:Name=“grdUpdateInterval” Visibility=“Visible” Width=“167” Margin=“3,0”>
<Grid.RowDefinitions>
<RowDefinition Height=“25.6”/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Content=“Update Interval (Minutes)” Height=“26” Grid.RowSpan=“2” VerticalAlignment=“Top” HorizontalAlignment=“Left” Margin=“3” />
<TextBox Grid.Row=“1” Name=“UpdateInterval” BorderBrush=“Black” Text=“360” VerticalAlignment=“Center” Margin=“10,4.4,32,3.6” Width=“125” HorizontalAlignment=“Center” />
</Grid>
</StackPanel>
I have a function that I call using Recursive $spBasicDRVSTART
Function Recursive ($Control)
{
$Controls = $Control.Children
foreach ($ctl in $Controls)
{
Write-Host $ctl.Name
if ($ctl.HasChildren)
{
Recursive $ctl
}
}
}
The function outputs the direct children of the stackpanel but not the children of the children.
e.g. <Label x:Name=“lblPullService” Grid.Row=“0” Margin=“3”>
<CheckBox x:Name=“chkPullService” Content=“Pull Service” VerticalContentAlignment=“Center” />
</Label>
lblPullService is written to the console but chkPullService is not.
I need to be able to do some checks on the control e.g. is it a checkbox control but I do not seem to be getting to it.
Any assistance on what I am doing wrong is appreciated.