Dialog Form not displaying IP Address information in Label

Ask your PowerShell-related questions, including questions on cmdlet development!
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.
This topic is 4 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
dca2rr
Posts: 11
Last visit: Fri Sep 06, 2019 9:50 am

Dialog Form not displaying IP Address information in Label

Post by dca2rr »

First of all, I am new to PowerShell Studio and I am loving it.
I am running PowerShell studio 2018.

Here is my script

$form1_Load = {
#TODO: Initialize Form Controls here
$env:computername
$label1.Text = "$env:COMPUTERNAME"
$label2.Text = 'Your Computer name is;'
$info = Get-NetIPAddress NetIPAddress | select-object IPAddress
$label3.Text = "$($info.Caption)"
$label1_Click = {
#TODO: Place custom script here

}
My label number 3 is not displaying anything in the form, I left more than enough space in the box to make sure the data fits. I am not getting any errors just nothing is displaying. Labels 1 and 2 are perfect. This is how it looks like, please help.
Attachments
2.png
2.png (8.37 KiB) Viewed 4875 times
1.png
1.png (7.37 KiB) Viewed 4875 times
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Dialog Form not displaying IP Address information in Label

Post by mxtrinidad »

Simple!

You are saving only the IPAddress property in your $Info variable.

Change $label3.Text = "$($info.Caption)" to $label3.Text = "$($info.IPAddress)"

It should work!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Dialog Form not displaying IP Address information in Label

Post by jvierra »

A much simpler way to the following:

$label3.Text = (Get-NetIPAddress -InterfaceAlias Wi-Fi).IpAddress |Out-String

This will return multiple addresses if that is what you want. Adapaters will nearly always have from 2 to 6 or more IP addresses. The name is called "InterfaceAlias" and is not the default.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Dialog Form not displaying IP Address information in Label

Post by jvierra »

You can also do it like this:

Code: Select all

$label3.Text = Get-NetAdapter Wi-Fi |Get-NetIPAddress | select -Expand IpAddress | Out-String
dca2rr
Posts: 11
Last visit: Fri Sep 06, 2019 9:50 am

Re: Dialog Form not displaying IP Address information in Label

Post by dca2rr »

You are awesome! That did it. Now, how can I display the IP’s in a column instead of a row? I really appreciate your expertise.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Dialog Form not displaying IP Address information in Label

Post by jvierra »

dca2rr wrote: Thu Aug 15, 2019 12:10 pm You are awesome! That did it. Now, how can I display the IP’s in a column instead of a row? I really appreciate your expertise.
That is what my example does.
dca2rr
Posts: 11
Last visit: Fri Sep 06, 2019 9:50 am

Re: Dialog Form not displaying IP Address information in Label

Post by dca2rr »

mxtrinidad wrote: Thu Aug 15, 2019 11:22 am Simple!

You are saving only the IPAddress property in your $Info variable.

Change $label3.Text = "$($info.Caption)" to $label3.Text = "$($info.IPAddress)"

It should work!
I hate to bug you mxtrinidad but, since you fixed my other problem I am hoping you can help me again. Now I need to display the OS Version ( build ) This is what I got but again is not displaying the OS build in the label.


$form1_Load={#TODO: Initialize Form Controls here
$os = (Get-CimInstance Win32_OperatingSystem).version
$label1.Text = "$($os.version)"}
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Dialog Form not displaying IP Address information in Label

Post by jvierra »

Simple.

$label1.Text = (Get-CimInstance Win32_OperatingSystem).version
dca2rr
Posts: 11
Last visit: Fri Sep 06, 2019 9:50 am

Re: Dialog Form not displaying IP Address information in Label

Post by dca2rr »

jvierra wrote: Mon Aug 19, 2019 12:21 pm Simple.

$label1.Text = (Get-CimInstance Win32_OperatingSystem).version
That worked perfect! thanks a million man
dca2rr
Posts: 11
Last visit: Fri Sep 06, 2019 9:50 am

Re: Dialog Form not displaying IP Address information in Label

Post by dca2rr »

dca2rr wrote: Mon Aug 19, 2019 12:29 pm
jvierra wrote: Mon Aug 19, 2019 12:21 pm Simple.

$label1.Text = (Get-CimInstance Win32_OperatingSystem).version
That worked perfect! thanks a million man
One more for you 😊

Hi guys,
Is there a way to exclude the 169.254 addresses? Also how do I get the actual Windows Version no the build number? Like this


Here is my script


$formComputerSupportInfor_Load = {
#TODO: Initialize Form Controls here
$env:computername
$label1.Text = "$env:COMPUTERNAME"
$label2.Text = 'Your Computer name is:'
$info = Get-NetIPAddress -AddressFamily ipv4
$label3.Text = "$($info.IPAddress)"
$label4.Text = 'IPV4 Information'
$os = (Get-CimInstance Win32_OperatingSystem).version
$label6.Text = (Get-CimInstance Win32_OperatingSystem).version
$label5.Text = 'Your Windows 10 Build is:'
Get-CimInstance

}
$label1_Click = {
#TODO: Place custom script here

}

$label3_Click={
#TODO: Place custom script here

}

Image[/img]img]
Attachments
3.png
3.png (7.97 KiB) Viewed 4592 times
Last edited by dca2rr on Fri Aug 23, 2019 6:31 am, edited 1 time in total.
This topic is 4 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked