• 获得Azure订阅LoadBalancer的脚本


    有客户希望可以通过一条命令获得一个Azure订阅中所有的负载均衡器。

    目前在Azure的powershell中是没有这中命令的。但我们可以通过脚本的方式实现。

    下面就是获得所有负载均衡的脚本:

     

    param(
    [Parameter(Mandatory=$true)]
    [String]$subscriptionId
    
    )
    $flag=0
    $subs=Get-AzureSubscription
    foreach($sub in $subs)
    {
      if($sub.subscriptionid -eq $subscriptionId)
      {  $flag=1  }
    }
    if($flag -eq 0)
    {
      Add-AzureAccount -Environment AzureChinaCloud
    }
    
    Select-AzureSubscription -SubscriptionId $subscriptionId
    
    
    $sers = Get-AzureService
    $result=@()
    foreach ($ser in $sers)
    {
      $vms = get-azurevm -ServiceName $ser.ServiceName
      foreach($vm in $vms)
      {
        
        $lbs=Get-AzureEndpoint -VM $vm | Where-Object {$_.LBSetName -ne $null}
        foreach ($lb in $lbs)
        {
          $vmObject = New-Object PSObject
          $vmObject | Add-Member -MemberType NoteProperty -Name "ServiceName" -Value $vm.ServiceName
          $vmObject | Add-Member -MemberType NoteProperty -Name "VMName" -Value $vm.Name
          $vmObject | Add-Member -MemberType NoteProperty -Name "LBType" -Value "SLB"
          $vmObject | Add-Member -MemberType NoteProperty -Name "SLBName" -Value $lb.LBSetName
          $vmObject | Add-Member -MemberType NoteProperty -Name "LocalPort" -Value $lb.LocalPort
          $vmObject | Add-Member -MemberType NoteProperty -Name "PubPort" -Value $lb.Port
          $vmObject | Add-Member -MemberType NoteProperty -Name "HashType" -Value $lb.LoadBalancerDistribution
          $result+= $vmObject
     
        }
        
        $ilbs=Get-AzureEndpoint -VM $vm | Where-Object {$_.InternalLoadBalancerName -ne $null}
        foreach ($ilb in $ilbs)
        {
          $vmObject = New-Object PSObject
          $vmObject | Add-Member -MemberType NoteProperty -Name "ServiceName" -Value $vm.ServiceName
          $vmObject | Add-Member -MemberType NoteProperty -Name "VMName" -Value $vm.Name
          $vmObject | Add-Member -MemberType NoteProperty -Name "LBType" -Value "ILB"
          $vmObject | Add-Member -MemberType NoteProperty -Name "SLBName" -Value $ilb.InternalLoadBalancerName
          $vmObject | Add-Member -MemberType NoteProperty -Name "LocalPort" -Value $ilb.LocalPort
          $vmObject | Add-Member -MemberType NoteProperty -Name "PubPort" -Value $ilb.Port
          $vmObject | Add-Member -MemberType NoteProperty -Name "HashType" -Value $ilb.LoadBalancerDistribution
          $result+= $vmObject
           }
         
      }
      
    }
    $result |Format-Table 

     用CLI也可以实现类似的功能。但输出是原始的输出格式:

    #!/bin/bash
    sers=`azure service list | awk '/China/ {print $2}'`
    for ser in $sers
    do
      slbs=`azure service load-balanced-set list $ser |awk '/(tcp|udp)/ {print $2}'`
      for slb in $slbs
      do
        azure service load-balanced-set show -b $slb $ser
      done
    done
  • 相关阅读:
    Xcode8 pod install 报错 “Generating Pods project Abort trap
    适配iOS10 的相关权限设置
    YTKNetworkConfig配置HTTPS请求
    HTTPS学习总结
    设置导航栏nav全透明
    更新 Python 库文件
    有道词典的本地/扩展/离线词库
    三国群英传2修改MOD基础
    添加/删除/修改Windows 7右键的“打开方式”
    Sublime Text安装Package Control
  • 原文地址:https://www.cnblogs.com/hengwei/p/5345563.html
Copyright © 2020-2023  润新知