【问题标题】:scan subnets for ilo ips扫描子网以查找 iLO ip
【发布时间】:2018-09-13 15:16:57
【问题描述】:

所以我有这个脚本:

$srvILO = '172.16.2.210'
$username='svcilo'
$password='xxxx'

$status_message = get-HPiLoFirmwareversion -Server $srvILO -Username $username -Password $password -DisableCertificateAuthentication -WarningAction SilentlyContinue | Select-Object -ExpandProperty STATUS_MESSAGE

if ($status_message -eq 'OK'){
Write-Host "Status OK"
Exit 0
}
else {
Write-Host "$status_message"
Exit 0
}

我希望将它部署在具有多个子网的多个客户处,并且 iLO 端口并不总是在同一个 ip 上。

有什么方法可以扫描子网以查找主机名的一部分,这总是不包括 ILO,并为分配给它的 ip 地址定义一个变量?

类似的东西 $ILO IP = test-connecten ...扫描子网192.168.0.210、192.168.1.210、192.168.2.210等...搜索包含dns的主机名。

【问题讨论】:

    标签: powershell networking dns


    【解决方案1】:

    您可以尝试这样的方法来扫描一个范围内的所有 IP

    $username='svcilo'
    $password='xxxx'
    $ipstart = "1"
    $ipend = "255"
    $ipgroupes = "172.168.2"
    $ipstart..$ipend  | ForEach-Object{
    $ip = "$ipgroupes.0" -replace "0$",$_ 
    
    $DNSName = Resolve-DnsName -Name $ip | Select NameHost
    
    
    
    if ($DNSName -like '*ILO*'){
    
        $status_message = get-HPiLoFirmwareversion -Server $ip -Username $username -Password $password -DisableCertificateAuthentication -WarningAction SilentlyContinue | Select-Object -ExpandProperty STATUS_MESSAGE
    
        if ($status_message -eq 'OK'){
            Write-Host "Status OK"
            Exit 0
            }
    
        else {
            Write-Host "$status_message"
            Exit 0
            }
    
    }
    
    
    
    }
    

    【讨论】:

    • 有什么方法可以在这个命令中使用 asterix? $ComputerName= ‘MetcorpDC01’ [System.Net.Dns]::GetHostAddresses(“$ComputerName”).IPAddressToString
    猜你喜欢
    • 2022-12-24
    • 1970-01-01
    • 2015-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多