Erwin Pombett
asked on
In powershell i have a function that return me the Ip after an URL, if i use it an loop i always receive an error, what am i doing wrong ?
Hello, i have a function that return as expected the ip after an URL when i call it on it's own.
but if i call my function from within a foreach loop my code ended into the catch block.
here 's the function -------------------------- ---------- ---------- ---------- -------
function GetIpAdresse
{
Param([String] $aServerName)
try{
$ip = [System.Net.Dns]::GetHostA ddresses($ aServerNam e)
$ipFinal = $ip[0].IPAddressToString
return $ipFinal
}
catch{
[system.exception]
write-host "ko pour url -> ip" + $_
}
finally
{}
}
-------------------------- ---------- ---------- ---------- -------
when i call it from
......
foreach($theServerName in $allServers.Values)
{
$tempIP = GetIpAdresse $theServerName.ToString()
}
.......
how can i deal with this, i can not find a solution.
thank you in advance for your help
toshi_
but if i call my function from within a foreach loop my code ended into the catch block.
here 's the function --------------------------
function GetIpAdresse
{
Param([String] $aServerName)
try{
$ip = [System.Net.Dns]::GetHostA
$ipFinal = $ip[0].IPAddressToString
return $ipFinal
}
catch{
[system.exception]
write-host "ko pour url -> ip" + $_
}
finally
{}
}
--------------------------
when i call it from
......
foreach($theServerName in $allServers.Values)
{
$tempIP = GetIpAdresse $theServerName.ToString()
}
.......
how can i deal with this, i can not find a solution.
thank you in advance for your help
toshi_
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hello Dan !
thank you for your reply,
$allServers is a hashtable
$allServers.Values is because i want to loop only over the ...values ;)
my values are string. to force that i added the "toString()" method....but nothing changes...
thank you for further help
thank you for your reply,
$allServers is a hashtable
$allServers.Values is because i want to loop only over the ...values ;)
my values are string. to force that i added the "toString()" method....but nothing changes...
thank you for further help
Can you post some of the data in your hashtable?
Dan
Dan
ASKER
this is when i'm debugging :
i have the correct value
[DBG]: PS C:\Users\pombette\Document s\WindowsP owerShell\ Modules>> $aServerName
"thetargetserer.domi.dom.d o" <- replaced for the question
[DBG]: PS C:\Users\pombette\Document s\WindowsP owerShell\ Modules>> [System.Net.Dns]::GetHostA ddresses($ aServerNam e)
Exception lors de l'appel de « GetHostAddresses » avec « 1 » argument(s) : « Hôte inconnu »
Au caractère Ligne:1 : 1
+ [System.Net.Dns]::GetHostA ddresses($ aServerNam e)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SocketException
i have the correct value
[DBG]: PS C:\Users\pombette\Document
"thetargetserer.domi.dom.d
[DBG]: PS C:\Users\pombette\Document
Exception lors de l'appel de « GetHostAddresses » avec « 1 » argument(s) : « Hôte inconnu »
Au caractère Ligne:1 : 1
+ [System.Net.Dns]::GetHostA
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SocketException
ASKER
Name Value
---- -----
eidIdp02 "anidp02.aspfr.cl"
eidAgentEdu "aserverid01.edu.tt.cl"
eidAgentAdNet02 "another02.xt.net.tt.cl"
i changed the values, you wont find anything for these servers...but it's the display i have for the hashtable
---- -----
eidIdp02 "anidp02.aspfr.cl"
eidAgentEdu "aserverid01.edu.tt.cl"
eidAgentAdNet02 "another02.xt.net.tt.cl"
i changed the values, you wont find anything for these servers...but it's the display i have for the hashtable
ASKER
thank you !!!!!!
by reading your file i noticed the difference. without quoting things everything is OK !!
toshi
by reading your file i noticed the difference. without quoting things everything is OK !!
toshi
Dan