Exclude IP from Dialog Form

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
Post Reply
dca2rr
Posts: 11
Joined: Thu Aug 15, 2019 9:25 am

Exclude IP from Dialog Form

Post by dca2rr » Tue Aug 27, 2019 8:02 am

The script below is working perfect, but how do I exclude IP addresses that start with 169.254?

Thanks in advance

$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:'
$label10.Text = 'Your Windows version is:'
$windows = (Get-ItemPropertyValue 'hklm:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name ReleaseId).windows
$label9.Text = (Get-ItemPropertyValue 'hklm:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name ReleaseId)


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

}

$label3_Click={
#TODO: Place custom script here

}

$label10_Click={
#TODO: Place custom script here

}

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

Re: Exclude IP from Dialog Form

Post by jvierra » Tue Aug 27, 2019 10:38 am

You can use the "Where-Object" CmdLet with the "-match" operator to filter unwanted values.

help where-object -online

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

Re: Exclude IP from Dialog Form

Post by dca2rr » Tue Aug 27, 2019 10:59 am

jvierra wrote:
Tue Aug 27, 2019 10:38 am
You can use the "Where-Object" CmdLet with the "-match" operator to filter unwanted values.

help where-object -online
Is you! I thought you were on vacation or something. I love the -online stuff, very cool. Thanks again...

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

Re: Exclude IP from Dialog Form

Post by dca2rr » Wed Aug 28, 2019 4:46 am

jvierra wrote:
Tue Aug 27, 2019 10:38 am
You can use the "Where-Object" CmdLet with the "-match" operator to filter unwanted values.

help where-object -online
What I am doing wrong here
(Get-NetIPAddress -AddressFamily ipv4).IPAddress | Where-Object IPAddress -Match "169*"

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

Re: Exclude IP from Dialog Form

Post by jvierra » Wed Aug 28, 2019 5:00 am

(Get-NetIPAddress -AddressFamily ipv4).IPAddress | Where-Object {$_.IPAddress -match '^169'}

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

Re: Exclude IP from Dialog Form

Post by dca2rr » Wed Aug 28, 2019 11:34 am

jvierra wrote:
Wed Aug 28, 2019 5:00 am
(Get-NetIPAddress -AddressFamily ipv4).IPAddress | Where-Object {$_.IPAddress -match '^169'}
Perfect! thanks again sir.

Post Reply