{"id":3457,"date":"2020-08-12T15:23:12","date_gmt":"2020-08-12T14:23:12","guid":{"rendered":"https:\/\/www.lieben.nu\/liebensraum\/?p=3457"},"modified":"2020-08-12T15:23:12","modified_gmt":"2020-08-12T14:23:12","slug":"get-tenant-id-using-azure-subscription-id","status":"publish","type":"post","link":"https:\/\/lieben.nu\/liebensraum\/2020\/08\/get-tenant-id-using-azure-subscription-id\/","title":{"rendered":"Get tenant ID using Azure Subscription ID"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">For a customer use case in an Azure Marketplace Managed Application scenario, I needed the ability to translate the (customers&#8217;) Azure Subscription ID (which is known to the publishing tenant) to a tenant ID. Using Get-AzSubscription, Lighthouse subscriptions don&#8217;t show the true tenant ID of the other tenant, but only show your own tenant ID.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following PS function can retrieve the tenant ID for you (<span style=\"text-decoration: underline;\">without authentication<\/span>):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nfunction get-tenantIdFromSubscriptionID($subId){\n    $response = try {(Invoke-WebRequest -UseBasicParsing -Uri \"https:\/\/management.azure.com\/subscriptions\/$($subId)?api-version=2015-01-01\" -ErrorAction Stop).BaseResponse} catch { $_.Exception.Response } \n    $stringHeader = $response.Headers.ToString()\n    return($stringHeader.SubString($stringHeader.IndexOf(\"login.windows.net\")+18,36))\n}\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>For a customer use case in an Azure Marketplace Managed Application scenario, I needed the ability to translate the (customers&#8217;) Azure Subscription ID (which is known to the publishing tenant) to a tenant ID. Using Get-AzSubscription, Lighthouse subscriptions don&#8217;t show the true tenant ID of the other tenant, but only show your own tenant ID. &hellip; <a href=\"https:\/\/lieben.nu\/liebensraum\/2020\/08\/get-tenant-id-using-azure-subscription-id\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Get tenant ID using Azure Subscription ID<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[5,39],"tags":[],"class_list":["post-3457","post","type-post","status-publish","format-standard","hentry","category-azure","category-powershell"],"_links":{"self":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/3457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/comments?post=3457"}],"version-history":[{"count":0,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/3457\/revisions"}],"wp:attachment":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media?parent=3457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/categories?post=3457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/tags?post=3457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}