To help you better we need some information from you.
*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***
Product, version and build: 2019 5.6.159
32 or 64 bit version of product: 64
Operating system: Windows 10
32 or 64 bit OS: 64
I am having trouble making a label have the correct text that comes from an XML file.
Code:
$buttonSEARCH_Click={
#TODO: Place custom script here
[xml]$file = (Get-Content 'c:\test\programdata\Server Configuration.xml')
$Node = $file.servers.server.Instances.Instance | Where-Object{$_.BindingHostName -eq $BindingURL}
$detailsLBL.text = $Node.name
}
END of code
Maybe it's just because I haven't used Powershell Studio in a long time. Any help would be appreciated. I have already confirmed that $Node variable works in regular powershell window, so I guess it's just a matter of syntax.
XML data to a label.text property
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: XML data to a label.text property
[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: XML data to a label.text property
You can run into trouble if you are getting an array back. Try using the Out-String cmdlet:
You can also run into the case where you are getting nothing back as well.
Code: Select all
$detailsLBL.text = $Node.name | Out-String
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: XML data to a label.text property
I already tried that before. the fact is I am getting nothing back. I start with detailsLBL.text with a default value of 'TEXT'. When it gets to reassign a value it assigns it as blank.
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: XML data to a label.text property
$detailsLBL is still equal to BLANK
I'm wondering if the .name is not an element for some reason? It worked fine in powershell ISE.
I'm wondering if the .name is not an element for some reason? It worked fine in powershell ISE.
Re: XML data to a label.text property
Without a sample of you XML it is not possible to know why this is happening. If you have multiple nodes then the code will need to be different.
Run the code at a PS prompt and inspect what is returned.
Run this at a prompt:
[xml]$xml = (Get-Content 'c:\test\programdata\Server Configuration.xml')
$xml.SelectNodes('//Instance/BindingHostName')
What does it return?
Post a single instance XML.
Run the code at a PS prompt and inspect what is returned.
Run this at a prompt:
[xml]$xml = (Get-Content 'c:\test\programdata\Server Configuration.xml')
$xml.SelectNodes('//Instance/BindingHostName')
What does it return?
Post a single instance XML.
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: XML data to a label.text property
this is the output you requested
xml Servers
--- -------
version="1.0" encoding="utf-8" Servers
xml Servers
--- -------
version="1.0" encoding="utf-8" Servers