locked
ASR-AddSingleLoadBalancer.ps1 Failure in Script RRS feed

  • Question

  • Attempting to add a script to an existing ASR recovery plan. The idea is to add two app servers to an internal load balancer. Found this script online and am running into trouble...

    https://gallery.technet.microsoft.com/scriptcenter/Add-single-load-balancer-8d5a6019

    Here is the output;

    Found the following VMGuid(s): 
    (VMGUIDA)
    (VMGUIDB)
    Found multiple VMs in the Recovery Plan
    Logging in to Azure...

    Selecting Azure subscription...

    (ASRVaultNameA)
    (VMNAMEA)
    Availability Set is present for VM: 

    (VMNAMEA)

    I found that it fails on the following line within the script, line 115

            #Join the VMs NICs to backend pool of the Load Balancer
            $ARMNic = Get-AzureRmResource -ResourceId $AzureVm.NetworkInterfaceIDs

    The message is;

    PS C:\> Get-AzureRmResource -ResourceId $AzureVm.NetworkInterfaceIDs[0]
    Cannot index into a null array.

    I am having a hard time deconstructing this script as I am not finding $AzureVm.NetworkInterfaceIDs[0] and only $AzureVM.NetworkProfile. It appears they are trying to get the NetworkID so they can associate it to the load balancer by name for the update to occur. 

            $ARMNic = Get-AzureRmResource -ResourceId $AzureVm.NetworkInterfaceIDs[0] 
            $Nic = Get-AzureRmNetworkInterface -Name $ARMNic.Name -ResourceGroupName $ARMNic.ResourceGroupName 
            $Nic.IpConfigurations[0].LoadBalancerBackendAddressPools.Add($LoadBalancer.BackendAddressPools[0]);         
            $Nic | Set-AzureRmNetworkInterface     
            Write-Output "Done configuring Load Balancing for VM" $AzureVm.Name  

    Can anyone help point me in the right direction? 

    Saturday, June 16, 2018 5:30 PM

Answers

  • Instead of this...

    $ARMNic = Get-AzureRmResource -ResourceId $AzureVm.NetworkInterfaceIDs[0] 

    Use this

    $ARMNic = Get-AzureRmResource -ResourceId $AzureVm.NetworkProfile.NetworkInterfaces.Id


    • Edited by Colin3Cloud Thursday, June 28, 2018 6:23 PM
    • Marked as answer by Colin3Cloud Thursday, June 28, 2018 6:23 PM
    Saturday, June 16, 2018 6:16 PM

All replies

  • Not seeing the ID attribute I want...

    PS C:\Users\ColinLanders\Desktop> get-azurermvm -Name AzureVM1  -ResourceGroupName RG1 | get-member


       TypeName: Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine

    Name                     MemberType Definition
    ----                     ---------- ----------
    Equals                   Method     bool Equals(System.Object obj)
    GetHashCode              Method     int GetHashCode()
    GetType                  Method     type GetType()
    ToString                 Method     string ToString()
    AvailabilitySetReference Property   Microsoft.Azure.Management.Compute.Models.SubResource AvailabilitySetReference {...
    DiagnosticsProfile       Property   Microsoft.Azure.Management.Compute.Models.DiagnosticsProfile DiagnosticsProfile ...
    DisplayHint              Property   Microsoft.Azure.Commands.Compute.Models.DisplayHintType DisplayHint {get;set;}
    Extensions               Property   System.Collections.Generic.IList[Microsoft.Azure.Management.Compute.Models.Virtu...
    HardwareProfile          Property   Microsoft.Azure.Management.Compute.Models.HardwareProfile HardwareProfile {get;s...
    Id                       Property   string Id {get;set;}
    Identity                 Property   Microsoft.Azure.Management.Compute.Models.VirtualMachineIdentity Identity {get;s...
    InstanceView             Property   Microsoft.Azure.Management.Compute.Models.VirtualMachineInstanceView InstanceVie...
    LicenseType              Property   string LicenseType {get;set;}
    Location                 Property   string Location {get;set;}
    Name                     Property   string Name {get;set;}
    NetworkProfile           Property   Microsoft.Azure.Management.Compute.Models.NetworkProfile NetworkProfile {get;set;}
    OSProfile                Property   Microsoft.Azure.Management.Compute.Models.OSProfile OSProfile {get;set;}
    Plan                     Property   Microsoft.Azure.Management.Compute.Models.Plan Plan {get;set;}
    ProvisioningState        Property   string ProvisioningState {get;set;}
    RequestId                Property   string RequestId {get;set;}
    ResourceGroupName        Property   string ResourceGroupName {get;}
    StatusCode               Property   System.Net.HttpStatusCode StatusCode {get;set;}
    StorageProfile           Property   Microsoft.Azure.Management.Compute.Models.StorageProfile StorageProfile {get;set;}
    Tags                     Property   System.Collections.Generic.IDictionary[string,string] Tags {get;set;}
    Type                     Property   string Type {get;set;}
    VmId                     Property   string VmId {get;set;}
    Zones                    Property   System.Collections.Generic.IList[string] Zones {get;set;}

    Saturday, June 16, 2018 5:51 PM
  • Instead of this...

    $ARMNic = Get-AzureRmResource -ResourceId $AzureVm.NetworkInterfaceIDs[0] 

    Use this

    $ARMNic = Get-AzureRmResource -ResourceId $AzureVm.NetworkProfile.NetworkInterfaces.Id


    • Edited by Colin3Cloud Thursday, June 28, 2018 6:23 PM
    • Marked as answer by Colin3Cloud Thursday, June 28, 2018 6:23 PM
    Saturday, June 16, 2018 6:16 PM
  • How did you get till there, My script is failing at the if condition itself. Failover direction is not azure it is giving the output.
    Wednesday, August 12, 2020 2:52 AM