none
Powershell MaxDeliveryCount attribute error for Get-AzServiceBusQueue command RRS feed

  • Question

  • I'm trying to change MaxDeliveryCount value to 1 instead of default value of 10 through PowerShell.
    I have another Dev environment where I have hundreds of queues which need to make this change. The below Powershell code seems to work fine but only once. When I try to run the script again I receive error for MaximumDeliveryCount attribute.


    Here is the error:

    PS C:\Users\test>     $Servicebus_queue.MaxDeliveryCount = 1

    The property 'MaxDeliveryCount' cannot be found on this object. Verify that the property exists and can be set.
    At line:1 char:5
    +     $Servicebus_queue.MaxDeliveryCount = 1
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : PropertyAssignmentException

    Here is the PowerShell code below:


    $Resourcegroup_name = "testrg"
    $Servicebus_namespace = "testingsb"
    $Servicebus_queuename = "testingsb_queue"

    $Servicebus_queue = (Get-AzServiceBusQueue -ResourceGroupName $Resourcegroup_name -Namespace $Servicebus_namespace).Name
    $Servicebus_queue

    $Servicebus_queue.foreach{
        $Servicebus_queue = Get-AzServiceBusQueue -ResourceGroupName $Resourcegroup_name -Namespace $Servicebus_namespace

        $Servicebus_queue.MaxDeliveryCount = 1

        Set-AzServiceBusQueue -ResourceGroupName $Resourcegroup_name -Namespace $Servicebus_namespace -Name $_ -InputObject $Servicebus_queue -Verbose
    }


    I believe this might be due to some kind of bug in PowerShell. Even after restarting PS, it doesn't work.

    I'm using PS version 5.1.17134.858 on Windows 10 Enterprise



    • Edited by Arj9 Friday, September 13, 2019 10:42 AM
    Friday, September 13, 2019 10:40 AM

All replies

  • Hi Arj9,

    You were sending only 'Name' property value to the variable $Servicebus_queue and then later were trying to get property named 'MaxDeliveryCount' under the variable $Servicebus_queue which ideally doesn't exist.

    Instead, you may use below script to accomplish your requirement.

    $Resourcegroup_name = "testrg"
    $Servicebus_namespace = "testingsb"
    $Servicebus_queuename = "testingsb_queue"
    
    $Servicebus_queue = Get-AzServiceBusQueue -ResourceGroupName $Resourcegroup_name -Namespace $Servicebus_namespace
    $Servicebus_queue
    
    $Servicebus_queue.foreach{
        $Servicebus_queue = Get-AzServiceBusQueue -ResourceGroupName $Resourcegroup_name -Namespace $Servicebus_namespace    
        $Servicebus_queue.MaxDeliveryCount = 1
        Set-AzServiceBusQueue -ResourceGroupName $Resourcegroup_name -Namespace $Servicebus_namespace -Name $_ -InputObject $Servicebus_queue -Verbose
    }

    Hope this helps! Cheers!
    Sunday, September 15, 2019 3:28 AM
    Moderator
  • Hi KrishnaG,

    Thanks for your reply. I tried your advise by removing the 'Name' property and looks good. But instead of using this command inside the foreach loop,'$Servicebus_queue = Get-AzServiceBusQueue -ResourceGroupName $Resourcegroup_name -Namespace $Servicebus_namespace

     I'm using it outside of the loop and using '$Servicebus_queue = $_ ' inside the loop which resolved the issue. This also helps in reducing the time taken to run one more extra command by the script for every loop.

    But appreciate your help. Thanks.


    Amit Joshi

    Monday, September 16, 2019 6:49 AM