Wednesday, August 19, 2020

SQL Server: Convert datetime from UTC to specific time zone

A clean and nice way to convert datetime from UTC to specific time zone using AT TIME ZONE.

This way can take into account DST too.

Sunday, April 12, 2020

Set-AzApiManagementApi : Value cannot be null. Parameter name: source

I came across an interesting error today when running the following Azure PowerShell scripts

$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroup -ServiceName $ApimName

Set-AzApiManagementApi -Context $ApiMgmtContext -ApiId $ApiId -SubscriptionKeyQueryParamName "auth-key"

The error is as below.

Set-AzApiManagementApi : Value cannot be null.
Parameter name: source
At line:1 char:1
+ Set-AzApiManagementApi -Context $ApiMgmtContext -ApiId $ApiId -Subscr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (System.Argument...ExecuteCmdlet():ArgumentNullException) [Set-AzApiManagementApi], ArgumentNullException
    + FullyQualifiedErrorId : Value cannot be null.
Parameter name: source,Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.SetAzureApiManagementApi


After a number of trial and error tests, I found that the missing parameter is '-Protocols'.

So the final script that worked was:

$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroup -ServiceName $ApimName

Set-AzApiManagementApi -Context $ApiMgmtContext -ApiId $ApiId -Protocols @('https') -SubscriptionKeyQueryParamName "auth-key"

What interesting is that the documentation at https://docs.microsoft.com/en-us/powershell/module/az.apimanagement/set-azapimanagementapi?view=azps-3.7.0 does not mention -Protocol is a required parameter.