Criei a seguinte função no meu arquivo de script $PROFILE:
function host($name, $server, $type) {
$FUNCNAME = $MyInvocation.MyCommand.Name
$argc = $args.Count
if ( $argc -eq 0 ) {
"=> Usage : $FUNCNAME `$name [`$server] [`$type=A]"
} elseif ( $argc -eq 1 ) {
$fqdn = $name -Replace('https?://|s?ftps?://','') -Replace('/.*$','')
(Resolve-DnsName $fqdn)[0].Name
(Resolve-DnsName $fqdn).IP4Address
} elseif ( $argc -eq 2 ) {
$fqdn = $name -Replace('https?://|s?ftps?://','') -Replace('/.*$','')
(Resolve-DnsName -name $fqdn -server $server)[0].Name
(Resolve-DnsName -name $fqdn -server $server).IP4Address
} elseif ( $argc -eq 3 ) {
$fqdn = $name -Replace('https?://|s?ftps?://','') -Replace('/.*$','')
if ( $type -eq "-4" ) {
$type = "A"
} elseif ( $type -eq "-6" ) {
$type = "AAAA"
} else {
$type = "A_AAAA"
}
(Resolve-DnsName -type $type -name $fqdn -server $server)[0].Name
(Resolve-DnsName -type $type -name $fqdn -server $server).IP4Address
} else {
Write-Warning "=> Not supported for the moment."
}
}
Tentei buscar o valor do argc
equivalente em C.
Então eu tentei $args.Count
, mas ele sempre retorna 0
de dentro da minha função.
Pode me ajudar ?