title: Get-AzKeyVault -InRemovedState call from Azure Function returns null even after long wait
body: <p>Here's the sequence of actions performed inside Azure powershell function -</p>
  <pre><code>if (Get-AzKeyVault -VaultName $name) {
      #This should Delete the KeyVault and put it into &quot;Removed&quot; state
      Remove-AzKeyVault -VaultName $name -Force
  }
  
  $timeout = New-TimeSpan -Minutes 16
  $stopWatch = [System.Diagnostics.Stopwatch]::StartNew()
  
  do{
     Write-Host &quot;Waiting for 2 minutes before checking InRemoved status of KeyVault '$name'&quot;
     Start-Sleep -s 120
     $vault = Get-AzKeyVault -InRemovedState | Where-Object { $_.VaultName -eq $name }
  } while ($stopWatch.ElapsedMilliseconds -lt $timeout.TotalMilliseconds -and $vault -eq $null)
              
  if ($vault) {
    Write-Host &quot;Removing '$name' Key Vault which is in Removed State&quot;
    Remove-AzKeyVault -VaultName $name -Force -InRemovedState -Location $vault.Location
  }
  </code></pre>
  <p>It seems, the &quot;Get-AzKeyVault -InRemovedState | Where-Object { $_.VaultName -eq $name }&quot; never returns the vault object and finally the function times out after the given timeout (16 minutes here). I tried from just putting a normal sleep of 20 seconds to this timeout based do-while and the Get-AzKeyVault -InRemovedState never gives already Removed Vault's object.</p>
  <p>The same logic works perfectly fine locally with no wait time required at all.</p>
  <p>Am I doing anything wrong here from Azure powershell function? Suggestions / help would be appreciated.</p>