Dialog Form not displaying IP Address information in Label

Ask your Windows 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.
dca2rr
Posts: 11
Joined: Thu Aug 15, 2019 9:25 am

Dialog Form not displaying IP Address information in Label

Post by dca2rr » Thu Aug 15, 2019 11:14 am

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 899 times
1.png
1.png (7.37 KiB) Viewed 899 times

User avatar
mxtrinidad
Site Admin
Posts: 328
Joined: Sun Mar 03, 2013 12:42 pm

Re: Dialog Form not displaying IP Address information in Label

Post by mxtrinidad » 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!

User avatar
jvierra
Posts: 13732
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Dialog Form not displaying IP Address information in Label

Post by jvierra » Thu Aug 15, 2019 11:55 am

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.

User avatar
jvierra
Posts: 13732
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Dialog Form not displaying IP Address information in Label

Post by jvierra » Thu Aug 15, 2019 11:58 am

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
Joined: Thu Aug 15, 2019 9:25 am

Re: Dialog Form not displaying IP Address information in Label

Post by dca2rr » 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.

User avatar
jvierra
Posts: 13732
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Dialog Form not displaying IP Address information in Label

Post by jvierra » Thu Aug 15, 2019 1:24 pm

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
Joined: Thu Aug 15, 2019 9:25 am

Re: Dialog Form not displaying IP Address information in Label

Post by dca2rr » Mon Aug 19, 2019 12:02 pm

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)"}
}

User avatar
jvierra
Posts: 13732
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Dialog Form not displaying IP Address information in Label

Post by jvierra » Mon Aug 19, 2019 12:21 pm

Simple.

$label1.Text = (Get-CimInstance Win32_OperatingSystem).version

dca2rr
Posts: 11
Joined: Thu Aug 15, 2019 9:25 am

Re: Dialog Form not displaying IP Address information in Label

Post by dca2rr » 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

dca2rr
Posts: 11
Joined: Thu Aug 15, 2019 9:25 am

Re: Dialog Form not displaying IP Address information in Label

Post by dca2rr » Fri Aug 23, 2019 4:53 am

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 616 times
Last edited by dca2rr on Fri Aug 23, 2019 6:31 am, edited 1 time in total.

Post Reply