skip to Main Content

I am using Azure powershell to create an APIM management resources as below:

.
.
.

$apimService = New-AzApiManagement `
    -ResourceGroupName $resGroupName `
    -Location $location `
    -Name $apimServiceName `
    -Organization $apimOrganization `
    -AdminEmail $apimAdminEmail `
    -VirtualNetwork $apimVirtualNetwork `
    -VpnType "Internal" `
    -Sku "Developer"

But, since APIM takes a lot of time to create, the powershell terminal times out and I have to reconnect. What happens is, the variable $apimService is set to null after reconnecting to the terminal again.

Because of that, I cannot execute the following command:

.
.
.

$proxyHostnameConfig = New-AzApiManagementCustomHostnameConfiguration `
  -Hostname $gatewayHostname `
  -HostnameType Proxy `
  -PfxPath $gatewayCertPfxPath `
  -PfxPassword $certPwd


// this command complains as variable $apimService is null 
$apimService.ProxyCustomHostnameConfiguration = $proxyHostnameConfig

What is the best way to preserve these variable values even after a 2 hours of time? Because APIm takes nearly 1 hour of time to complete when SKU is Developer

Can someone please help me?

Thank you,
Best Regards

2

Answers


  1. I tried to reproduce the same in my environment and below is the result

    I have used below powershell script to create an API Management

    Connect-AzAccount
    New-AzResourceGroup -Name myResourceGroup -Location WestUS
    $global:Head = New-AzApiManagement -ResourceGroupName myResourceGroup -Location "West US"-Organization "venkatapitest" -AdminEmail "[email protected]" -Sku "Developer"
    

    When i ran the above powershell commands, API Management got is created successfully without getting timedout error, like below.

    enter image description here

    I have tested same script in Azure Cloud Shell.

    enter image description here

    $global . This will ensure global scope which will allow you to get values in console.

    Login or Signup to reply.
  2. Once it’s finished creating, you can use Get-AzApiManagement to repopulate your variable.

    $apimService = Get-AzApiManagement -Name [Name] -ResourceGroupName [RGName]
    

    You’ll also need to do Set-AzApiManagement to actually apply the change.

    $apimService | Set-AzApiManagement
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search