Getting the Lease already present“,”message“:”Lease already present“ exception in PowerShell while executing the ”Set-AzureRmResource -Force" command RRS feed

  • Question

  • Getting the following exception in PowerShell while executing the "Set-AzureRmResource -Force"

    command parallel for multiple web tests in Azure environment. Please help on this issue.

    The pipeline has been stopped.      + CategoryInfo          : CloseError: (:) [Set-AzureRmResource], PipelineStoppedException      + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.SetAzureResourceCmdlet      + PSComputerName        : localhost   {"code":"Lease already present","message":"Lease already   present","innererror":{"diagnosticcontext":"2a3350d9-c78f-4572-9385-24ed387070b3","time":"2016-09-26T12:09:30.8564457Z"}}      + CategoryInfo          : CloseError: (:) [Set-AzureRmResource], ErrorResponseMessageException      + FullyQualifiedErrorId : Conflict,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.SetAzureResourceCmdlet      + PSComputerName        : localhost


       Please find the code below.

     workflow workflow1{    

    function DoRequest($webTestName){        


    Set-AzureRmContext -SubscriptionID "cb83ec7a-4da9-4509-90ef-    1041ff23aab2"
    = Get-AzureRmResource -ResourceGroupName "Default-        ApplicationInsights-CentralUS" -ResourceType 'Microsoft.Insights/WebTests' -ResourceName $webTestName  -ApiVersion "2015-05-01"

    .Properties.Enabled = "False"   #Disable Web Test.

    | Set-AzureRmResource -Force          

     # "Serial"
        $startTime = get-date
        foreach($row in $DataTable)
          DoRequest $row
        $serialElapsedTime = "elapsed time (serial foreach loop): " + ((get-date) -   $startTime).TotalSeconds

    #  "======================================================="   
    = get-date
    -parallel ($row in $DataTable)   
    # Start-Sleep -seconds 5     
    DoRequest $row.WebTest_Name     

    = "elapsed time (parallel foreach loop): " + ((get-date) - $startTime).TotalSeconds   




    • Edited by vijay vanam Tuesday, September 27, 2016 1:13 PM
    Tuesday, September 27, 2016 9:25 AM

All replies

  • YOU can't keep logging into Azure.  Login once then run your tests.

    This is missing the correct variable"


    should be:



    Tuesday, September 27, 2016 9:52 AM
  • While copying the code $ symbol is missed for the webTestName variable.

    Added the serial process code also and it is working fine for serial processing. The problem is, when more than one web test try to execute the Set-AzureRmResource command, we are getting the above mentioned exception. 

    When I googled the above issue, got the information that it is internally try to access the blob storage and it is locked by one process and meantime other process try to access it.

    • Edited by vijay vanam Tuesday, September 27, 2016 1:15 PM
    Tuesday, September 27, 2016 1:09 PM