get content from xml and show it in a lable

Hello all,
I’m very new in powershell and this are my first stepps and hope someone could help me.

I get a content from a xml file. The displayname from it is loaded into a combox and this is working. What i try to do now is, if i choose “Street” in the combobox in another lable the “streetAddress” should be show. Here’s the code i have until now. The line “$label1.Text = ???” is where i don’t know to solve :-).

thanks in advance

$button1_Click={
	$XMLfile = [XML] (Get-Content -path 'I:\Sonstiges\scripting\PowerShell\PowerShell Studio\Projects\Admin\Settings.xml')
	$XMLContent = $XMLfile.Exchange.attribut
	$XMLContent | select ID, displayName, exchangeName
	
#	$combobox1.Items.Clear()
	foreach ($att in $XMLContent)
	{
		Update-ComboBox -ComboBox $combobox1 -Items $att.displayname -Append
		Write-Host $att	
	}
	
	$label1.Text = ????????
	
}

 

 

Here’s the xml:
<Exchange>
<attribut ID=“1”>
<displayName>Office</displayName>
<exchangeName>Office</exchangeName>
</attribut>
<attribut ID=“2”>
<displayName>Street</displayName>
<exchangeName>streetAddress</exchangeName>
</attribut>
<attribut ID=“3”>
<displayName>City</displayName>
<exchangeName>City</exchangeName>
</attribut>
</Exchange

The XML code should be:

$XMLfile = [XML] (Get-Content -path 'I:\Sonstiges\scripting\PowerShell\PowerShell Studio\Projects\Admin\Settings.xml')
$XMLContent = $XMLfile.Exchange.attribut | 
                Select ID, displayName, exchangeName

This is writing the output to the host, not saving to a variable:

$XMLContent | select ID, displayName, exchangeName

As far as the label, you need to create an event for the combobox:

$ComboBox1_SelectedIndexChanged=

This would trigger when anything is changed in the comboxbox, do something. The next issue you are going to run into is scope. If you are trying to get additional information from the XML based on the select item, then you need to ensure that it’s available to the entire script:

$Script:XMLfile = [XML] (Get-Content -path 'I:\Sonstiges\scripting\PowerShell\PowerShell Studio\Projects\Admin\Settings.xml')
$XMLContent = $XMLfile.Exchange.attribut | 
                Select ID, displayName, exchangeName

Then in your Combobox event something like:

$label1.Text = $xmlContent | Where{$_.DisplayName -eq $comboBox.SelectedText} | Select -ExpandProperty ExchangeName

This is a bit advanced as a beginner project as you are working with .NET, Powershell, etc., but there are lots of examples posted out there on forms. None of the items I posted are tested, just pseudo code to get you in the right direction.