NAMEWITHELD12
asked on
I want to learn about exception handling in power shell I am reading and looking over the script now and really dont know what i am doing !
I want this script to just list the found ips and then if it does not find them return a "*"
right now when I run it I get
I am not sure this is even an "exception"
nd
Test-Connection : Testing connection to computer '192.168.5x.39' failed: A non-recoverable error occurred during a database lookup
At C:\Users\Bks\Desktop\ipsca n.ps1:8 char:47
+ $startip..$endip | foreach{test-connection <<<< -ComputerName $startsubnet$_ -count 1} | select -expandproperty ipv4address | select -expandproperty ipaddresstostring | foreach{[System.Net.Dns]:: GetHostByA ddr
ess("$_")}
+ CategoryInfo : ResourceUnavailable: (192.168.5x.39:String) [Test-Connection], PingException
+ FullyQualifiedErrorId : TestConnectionException,Mi crosoft.Po werShell.C ommands.Te stConnecti onCommand
T$startrange = read-host "Enter a start IP"
$endrange = read-host "Enter an end IP"
$startsubnet = "$($startrange.Split(".")[ 0]).$($sta rtrange.Sp lit(".")[1 ]).$($star trange.Spl it(".")[2] )."
$endsubnet = "$($endrange.Split(".")[0] ).$($endra nge.Split( ".")[1]).$ ($endrange .Split("." )[2])."
if ($startsubnet -eq $endsubnet) {
$startip = $($startrange.Split(".")[3 ])
$endip = $($endrange.Split(".")[3])
$startip..$endip | foreach{test-connection -ComputerName $startsubnet$_ -count 1} | select -expandproperty ipv4address | select -expandproperty ipaddresstostring | foreach{[System.Net.Dns]:: GetHostByA ddress("$_ ")}
} else {
write-host "Start subnet was not the same as the end subnet"
}
right now when I run it I get
I am not sure this is even an "exception"
nd
Test-Connection : Testing connection to computer '192.168.5x.39' failed: A non-recoverable error occurred during a database lookup
At C:\Users\Bks\Desktop\ipsca
+ $startip..$endip | foreach{test-connection <<<< -ComputerName $startsubnet$_ -count 1} | select -expandproperty ipv4address | select -expandproperty ipaddresstostring | foreach{[System.Net.Dns]::
ess("$_")}
+ CategoryInfo : ResourceUnavailable: (192.168.5x.39:String) [Test-Connection], PingException
+ FullyQualifiedErrorId : TestConnectionException,Mi
T$startrange = read-host "Enter a start IP"
$endrange = read-host "Enter an end IP"
$startsubnet = "$($startrange.Split(".")[
$endsubnet = "$($endrange.Split(".")[0]
if ($startsubnet -eq $endsubnet) {
$startip = $($startrange.Split(".")[3
$endip = $($endrange.Split(".")[3])
$startip..$endip | foreach{test-connection -ComputerName $startsubnet$_ -count 1} | select -expandproperty ipv4address | select -expandproperty ipaddresstostring | foreach{[System.Net.Dns]::
} else {
write-host "Start subnet was not the same as the end subnet"
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER