Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get Azure API Management Git Credential Password
[Parameter(Mandatory = $True)]
[Parameter(Mandatory = $True)]
[Parameter(Mandatory = $True)]
$KeyType = 'primary',
$ExpiryTimespan = (New-Timespan -Hours 2)
$context = New-AzureRmApiManagementContext -ResourceGroupName $ResourceGroup -ServiceName $ServiceName
// Correction thanks to @Shaun Titus
$expiry = (Get-Date).ToUniversalTime() + $ExpiryTimespan
$parameters = @{
"keyType"= $KeyType
"expiry"= ('{0:yyyy-MM-ddTHH:mm:ss.000Z}' -f $expiry)
$resourceId = '/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.ApiManagement/service/{2}/users/git' -f $SubscriptionId,$ResourceGroup,$ServiceName
$gitUsername = 'apim'
$gitPassword = (Invoke-AzureRmResourceAction -Action 'token' -ResourceId $resourceId -Parameters $parameters -ApiVersion '2016-10-10' -Force).Value
return @{
GitUsername = $gitUsername
GitPassword = $gitPassword
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment