美文网首页
批量修改azure内网地址为静态

批量修改azure内网地址为静态

作者: 秋幻旎苏 | 来源:发表于2018-04-17 10:14 被阅读0次

一.查看所有的动态ip

#获取所有的vm
$vms = get-azurermvm
#获取所有的网络接口
$nics = get-azurermnetworkinterface  | where VirtualMachine -NE $null #skip Nics with no VM
#遍历每一个网络接口
foreach($nic in $nics)
{
    $vm = $vms | where-object -Property Id -EQ $nic.VirtualMachine.id
    $prv =  $nic.IpConfigurations | select-object -ExpandProperty PrivateIpAddress
    $alloc =  $nic.IpConfigurations | select-object -ExpandProperty PrivateIpAllocationMethod
    $gr = $vm.ResourceGroupName
   #判断alloc 是否是Dynamic
    if ($alloc -eq "Dynamic")
    {
       Write-Output "$($vm.Name) : $prv , $alloc ,$gr"
    }
}

二.按照资源组修改

#定义资源组
$RG = "xxx"   
$vms = get-azurermvm -ResourceGroupName $RG

$nics = get-azurermnetworkinterface -ResourceGroupName $RG | where VirtualMachine -NE $null #skip Nics with no VM
foreach($nic in $nics)
{
    $vm = $vms | where-object -Property Id -EQ $nic.VirtualMachine.id
    $prv =  $nic.IpConfigurations | select-object -ExpandProperty PrivateIpAddress

    $alloc =  $nic.IpConfigurations | select-object -ExpandProperty PrivateIpAllocationMethod
    if ($alloc -eq "Dynamic")
    {
     $nic.IpConfigurations[0].PrivateIpAllocationMethod = 'Static'
     Set-AzureRmNetworkInterface -NetworkInterface $nic
     $IP = $nic.IpConfigurations[0].PrivateIpAddress
    }
}

三.修改所有动态

$vms = get-azurermvm 
$nics = get-azurermnetworkinterface  | where VirtualMachine -NE $null #skip Nics with no VM
foreach($nic in $nics)
{
    $vm = $vms | where-object -Property Id -EQ $nic.VirtualMachine.id
    $prv =  $nic.IpConfigurations | select-object -ExpandProperty PrivateIpAddress

    $alloc =  $nic.IpConfigurations | select-object -ExpandProperty PrivateIpAllocationMethod
    if ($alloc -eq "Dynamic")
    {
     $nic.IpConfigurations[0].PrivateIpAllocationMethod = 'Static'
     Set-AzureRmNetworkInterface -NetworkInterface $nic
     $IP = $nic.IpConfigurations[0].PrivateIpAddress
    }
}

相关文章

网友评论

      本文标题:批量修改azure内网地址为静态

      本文链接:https://www.haomeiwen.com/subject/annuuxtx.html