0

所以我一直在抨击知识库,试图看看什么是最好的。

使用 MDT / WDS 设置几台 BareBone 机器,我列出了主机名、ip 和 mac 地址。我可以将其添加到 txt 文件中,将 MAC 地址读取到唯一连接的 NIC - 将其与 txt 文件中的列表进行比较,然后获取变量以应用正确的主机名、IP 等。MDT 并没有任何动态设置应用主机名和 Nics 时。有人有工作吗?

我在哪里

$CSV = import-csv "c:\Scripts\IPInfo.txt"

Foreach ($Item in $CSV)
{
$MAC = $Item.MacAddress

$MAC_CMD = (Get-WmiObject win32_networkadapterconfiguration -ComputerName $env:COMPUTERNAME | Where Macaddress -eq $MAC | Select-Object -Expand macaddress) -join ","

$MAC_Dash = $MAC_CMD -replace ":", "-"
#Write-host $MAC_DASH

$ActiveNic =  Get-NetAdapter | where MacAddress -EQ $MAC_Dash | select -ExpandProperty name
#Write-Host "$ActiveNic"

#Write-Host "(in the loop) ip: $Computer"

if ($MAC_CMD -eq $Item.MacAddress){
$Computer = $Item.ComputerName
$IPaddress = $Item.IPAddress
$Subnet = $Item.SubnetMask
$GateWay = $Item.Gateway
$DNS1 = $Item.Dns1
$DNS2 = $Item.Dns2
}

}

Write-Host $ActiveNic

到目前为止,txt 有以下内容

computerName,IPAddress,SubnetMask,Gateway,Dns1,Dns2
devops-bg,10.1.0.57,255.255.255.0,10.1.0.1,10.1.0.18,10.1.0.13,

理论上,id 喜欢获取“活动”网卡的 mac 地址,然后将其与 txt 文件进行比较

4

0 回答 0