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
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.