There are customers who want to get all the load balancers in an Azure subscription with a single command.
There is no such command in PowerShell for Azure at this time. But we can do it in a script way.
Here is the script that gets all the load balancing:
param([Parameter (Mandatory=$true)][string]$subscriptionId)$flag=0$subs=get-azuresubscriptionforeach($sub inch $subs){ if($sub. SubscriptionId-eq $subscriptionId) { $flag=1 }}if($flag -eq0) {Add-azureaccount-Environment Azurechinacloud} Select-azuresubscription-subscriptionid$subscriptionId$sers= get-Azureservice$result[Email protected]()foreach($ser inch $sers){ $vms= Get-azurevm-servicename$ser. ServiceNameforeach($VM inch $vms) { $lbs=get-azureendpoint-vm$VM| Where-object {$_. Lbsetname-ne $null} foreach($lb inch $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 inch $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
Get scripts for Azure subscription LoadBalancer