Given subscription key - how to find associated user?

Martin Kallukalam 170 Reputation points

How do I find the user associated with a subscription key?
I understand I can find Sub key associated with a user. But is there a way to find User associated with a specific sub key?

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,935 questions
0 comments No comments
{count} votes

Accepted answer
  1. SwathiDhanwada-MSFT 18,551 Reputation points

    @Martin Kallukalam Here is sample script where it checks all the apim instances within your subscription to identify the respective subscription Id and user who owns it. Kindly fill in the respective values where "xxx" is mentioned.

    try {
        "Logging in to Azure..."
        Connect-AzAccount  -Tenant "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" 
    catch {
        Write-Error -Message $_.Exception
        throw $_.Exception
    $subscriptions = Get-AzSubscription -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"
    Set-AzContext -Subscription $subscriptions[0]
    $apiminstances = Get-AzApiManagement
    foreach (  $apim in $apiminstances) {
        $apimContext = New-AzApiManagementContext -ResourceGroupName $apim.ResourceGroupName -ServiceName $apim.Name
        $sId = Get-AzApiManagementSubscription -Context $apimContext
        foreach ($s in $sId) {
            $subKey = Get-AzApiManagementSubscriptionKey -Context $apimContext -SubscriptionId $s.SubscriptionId 
            if ($subKey.PrimaryKey -eq "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -or $subKey.SecondaryKey -eq "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") {
                $subtemp = Get-AzApiManagementSubscription -context $apimContext -SubscriptionId $s.SubscriptionId
                $user = Get-AzApiManagementUser -Context $apimContext -UserId $subtemp.UserId
                Write-Host "Subscription ID: " + $s.SubscriptionId + " User ID: " + $user.Id + " User Email: " + $user.Email
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful