Powershell 从CSV文件为网络接口卡设置Azure DNs设置
我正在尝试为Azure上的networkinterface卡设置DNS设置。我有一个CSV文件,它有服务器名、NIC、dnsip1、dnsip2 我以为会是这样的Powershell 从CSV文件为网络接口卡设置Azure DNs设置,powershell,azure,scripting,dns,Powershell,Azure,Scripting,Dns,我正在尝试为Azure上的networkinterface卡设置DNS设置。我有一个CSV文件,它有服务器名、NIC、dnsip1、dnsip2 我以为会是这样的 Import-CSV C:\temp\test.csv -Header rgName,NIC,DNSIP1,DNSIP2 | Foreach-Object { $n = Get-AzureRmNetworkInterface -Name $_.nic -ResourceGroupName $_.rgname $n.DnsSettin
Import-CSV C:\temp\test.csv -Header rgName,NIC,DNSIP1,DNSIP2 | Foreach-Object {
$n = Get-AzureRmNetworkInterface -Name $_.nic -ResourceGroupName $_.rgname $n.DnsSettings.DnsServers = '$_.DNSIP1','$_.DNSIP2'
}
我是否可以使用$n变量并在循环中不断重新分配它,我已经尝试过了,并且不断得到提示
cmdlet ForEach-Object at command pipeline position 1
Supply values for the following parameters:
Process[0]:
您应该使用来设置DNS设置。下面的脚本应该适合您
$csv="d:\nic.csv"
$NICS=Import-Csv $csv
ForEach ($kvp in $NICS){
$nic = Get-AzureRmNetworkInterface -ResourceGroupName $kvp.rgName -Name $kvp.NIC
$nic.DnsSettings.DnsServers.Add($kvp.DNSIP1)
$nic.DnsSettings.DnsServers.Add($kvp.DNSIP2)
$nic | Set-AzureRmNetworkInterface
}
您好,答案对您有用吗?
获取AzureRmNetworkInterface
只能获取NIC信息。如果要修改它,应使用Set-AzureRmNetworkInterface
。