lundi 30 mars 2015

PowerShell - why doesn't certain request types work?

This is really odd to me.. The ones for http and https appear fine.. The ones for port 8080 and 8443 do not..



$ip="1.2.3.4"
$urls = "http://$ip","http://"$ip":8080","https://$ip","https://"$ip":8443"
foreach ($u in $urls)
{
"$u"
}


The results show:



PS C:\Documents and Settings\user> D:\WORK\ps\test.ps1
Unexpected token 'ip' in expression or statement.
At D:\WORK\ps\test.ps1:2 char:37
+ $rsaurls = "http://$ip","http://"$ip <<<< ":8080","https://$ip","https://"$ip":8443"
+ CategoryInfo : ParserError: (ip:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken


If we remove the quoting..



$ip="1.2.3.4"
$urls = "http://$ip","http://$ip:8080","https://$ip","https://$ip:8443"
foreach ($u in $urls)
{
"$u"
}

And the results show:
PS C:\Documents and Settings\user> D:\WORK\ps\test.ps1
http://1.2.3.4
http://
https://1.2.3.4
https://


I think I need to escape the ":"..


I am closer..



$ip="1.2.3.4"
$urls = "http://$ip","http://$ip^:8080","https://$ip","https://$ip^:8443"
foreach ($u in $urls)
{
"$u"
}


and the results:



PS C:\Documents and Settings\user> D:\WORK\ps\test.ps1
http://1.2.3.4
http://1.2.3.4^:8080
https://1.2.3.4
https://1.2.3.4^:8443


Thanks!





Aucun commentaire:

Enregistrer un commentaire