所以我有这个脚本:
$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的主机名。
您可以尝试这样的方法来扫描一个范围内的所有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
}
}
}