Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8861969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:36:53+00:00 2026-06-14T15:36:53+00:00

The below doesn’t work. I understand my way of writing isn’t the most efficient,

  • 0

The below doesn’t work. I understand my way of writing isn’t the most efficient, but I learning PowerShell the hard way.

What I’m trying to do with this script is:

Firstly, find the IP address on the local computer (I haven’t included that bit of the script here, but it’s represented by the “169.254.2.2” in the $IPAddress variable)

Secondly, if the the IP Address is valid (i.e not 169.254) continue with the script (represented by the ‘Write-Host’). If it isn’t valid prompt the user so they may take action, and then when they click ok, find the IP address again and therefore loop until the IP address is valid.

The script kind of works until I put the IPAdressCheck function around that part of the script, and then it does nothing

function IPDialog {

$IPDia= [System.Windows.Forms.MessageBox]::show( "This computer doesn't have a vaild IP Address. 
Please resolve and click OK." , "No Network Connection" , 1 ) 
if ($IPDia -eq "OK" ){IPAddressCheck} 
else
{
exit
}
  }


 function IPAddressCheck{
$IPAddress = "169.254.2.2"
switch ($IPAddress){
    {($_ -like "0.*") -or ($_ -like "169.254.*")} {IPDialog}
    default {write-host 'Continue Script'}
      }

}   

Any guidance welcomed and grateful

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:36:54+00:00Added an answer on June 14, 2026 at 3:36 pm

    I got it working after sitting back and thinking about it for a while.

    Here’e the working code, well I think it works, I’ve only partiality tested it. If anyone wishes to share their opinion of how to refine it or make it better I’d gladly hear it, but I’m happy to have it working.

    function Check-IP
    {
    $IPSiteAddress = Get-IPAddress
    if ($IPSiteAddress -like "0.*" -or $IPSiteAddress -like "169.254.*") {DialogBox-IP}
    }
    
    function Get-IPAddress
    {
    (Get-WmiObject Win32_NetworkAdapterConfiguration |
    Where { $_.IPAddress } |
    Select -Expand IPAddress).split('.')[0..2] -join '.'
    }
    
    function DialogBox-IP
    {
    $IPDialog = [System.Windows.Forms.MessageBox]::show( "This computer doesn't have a valid IP Address. 
    Please correct the IP Address and click OK, or click Cancel to exit.","No Network Connection",1) 
    if ($IPDialog -eq "OK") {Check-IP} else {exit}
    }
    
    Check-IP
    $IPSiteAddress = Get-IPAddress
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find a subpalindrome in Java. But the below code doesn't provide
It works perfectly from the admin site. But the code below doesn't work properly(some
The jQuery below doesn't work but when the var link is equal to file:///C:/Users/USER/Desktop/test%20page/Home.html
I can't understand why the code below doesn't work. The client sends a message
Directory.CreateDirectory(@C:\test); Works great. I'm able to create the folder. BUT code below doesn't work.
The code below doesn't seem to work or find anything on an array. I'm
The jQuery ajax script below doesn't work on my site if url is without
This code below doesn't work correctly since my MFC program is in unicode circumstance.
Could anyone help me in assessing why the code below doesn't work. I'm using
I've implemented the jQuery slider UI in the page below but it doesn't seem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.