-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit from GitHub Actions (Generate Site)
- Loading branch information
Showing
14 changed files
with
8,309 additions
and
7,411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,312 @@ | ||
<!DOCTYPE html> | ||
<!--[if IE]><![endif]--> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>Get Tenant ID | PnP Samples </title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" "=""> | ||
<meta name="title" content="Get Tenant ID | PnP Samples "> | ||
<meta name="generator" content="docfx 2.56.7.0"> | ||
<meta name="description" content="A sample gallery of scripts to manage all things Microsoft 365."> | ||
|
||
<!-- Social Media --> | ||
<meta property="og:locale" content="en_GB"> | ||
<meta property="og:title" content="Get Tenant ID | PnP Samples "> | ||
<meta property="og:type" content="website"> | ||
<meta property="og:url" content="https://pnp.github.io/script-samples"> | ||
<meta property="og:image" content="https://pnp.github.io/script-samples/assets/social-media-screenshot.png"> | ||
<meta property="og:image:alt" content="Screenshot example of the PnP Script Samples Site"> | ||
<meta property="og:site_name" content="PnP Script Samples"> | ||
<meta name="msvalidate.01" content="04EFEDA66EC42C08A1247C979E2F9ADD"> | ||
<meta property="og:description" content="A sample gallery of scripts to manage all things Microsoft 365."> | ||
|
||
<link rel="shortcut icon" href="https://c.s-microsoft.com/favicon.ico?v2"> | ||
<link rel="stylesheet" href="../styles/docfx.vendor.css"> | ||
<link rel="stylesheet" href="../styles/docfx.css"> | ||
<link rel="stylesheet" href="../styles/main.css"> | ||
<link rel="stylesheet" href="../styles/extra.css"> | ||
<link rel="stylesheet" href="../styles/filter.css"> | ||
<link rel="stylesheet" href="../styles/site.css"> | ||
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"> | ||
<meta property="docfx:navrel" content="../toc.html"> | ||
<meta property="docfx:tocrel" content="../toc.html"> | ||
|
||
|
||
<meta property="docfx:newtab" content="true"> | ||
<script type="text/javascript"> | ||
(function(c,l,a,r,i,t,y){ | ||
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)}; | ||
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i; | ||
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y); | ||
})(window, document, "clarity", "script", "8j6pedl344"); | ||
</script> | ||
</head> <body data-spy="scroll" data-target="#affix" data-offset="120"> | ||
<div id="wrapper"> | ||
<header> | ||
|
||
<nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation"> | ||
<div class="container"> | ||
<div class="github-mark"> | ||
<a href="https://github.com/pnp/script-samples" title="Go to repository"> | ||
<div class="github-wrapper"> | ||
<div class="github-icon"> | ||
<img src="https://pnp.github.io/script-samples/assets/icons/github-light-64px.png" alt="GitHub Icon Image"> | ||
</div> | ||
<div class="github-repository"> | ||
<span>GitHub</span> | ||
<ul class="github-facts"> | ||
<li> | ||
<i class="fa fa-code-fork" aria-hidden="true"></i> | ||
<span class="github-forks"></span> | ||
</li> | ||
<li> | ||
<i class="fa fa-star-o" aria-hidden="true"></i> | ||
<span class="github-stars"></span> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</a> | ||
</div> | ||
<div class="navbar-header"> | ||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar"> | ||
<span class="sr-only">Toggle navigation</span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
</button> | ||
<a class="navbar-brand" href="../index.html"> | ||
<img id="logo" class="svg" src="../assets/logo.svg" alt=""> | ||
</a> </div> | ||
<div class="collapse navbar-collapse" id="navbar"> | ||
<form class="navbar-form navbar-right" role="search" id="search"> | ||
<div class="form-group"> | ||
<label class="glyphicon glyphicon-search" for="search-query"></label> | ||
<input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off"> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</nav> </header> | ||
<div role="main" class="container body-content hide-when-search"> | ||
<div class="article row grid"> | ||
<div class="col-md-12"> | ||
<article class="content wrap" id="_content" data-uid=""> | ||
<div class="contribution-panel mobile-hide pull-right"> | ||
<a href="https://github.com/pnp/script-samples/blob/main/scripts/aad-get-tenantid/README.md/#L1" title="Improve this Doc" class="improve-doc-lg"><i class="glyphicon glyphicon-pencil"></i></a> | ||
</div> | ||
<h1 id="get-tenant-id">Get Tenant ID</h1> | ||
|
||
<h2 id="summary">Summary</h2> | ||
<p>These are 2 practical scripts I have to get Tenant ID from either a domain name or from a Subscriptionis ID.</p> | ||
<p>These are simple, but very useful to be combined in other scripts.</p> | ||
<div class="tabGroup" id="tabgroup_CeZOj-G++Q"> | ||
<ul role="tablist"> | ||
<li role="presentation"> | ||
<a href="#tabpanel_CeZOj-G++Q_ps" role="tab" aria-controls="tabpanel_CeZOj-G++Q_ps" data-tab="ps" tabindex="0" aria-selected="true">PowerShell (Domain)</a> | ||
</li> | ||
<li role="presentation"> | ||
<a href="#tabpanel_CeZOj-G++Q_ps1" role="tab" aria-controls="tabpanel_CeZOj-G++Q_ps1" data-tab="ps1" tabindex="-1">PowerShell (Subscription)</a> | ||
</li> | ||
</ul> | ||
<section id="tabpanel_CeZOj-G++Q_ps" role="tabpanel" data-tab="ps"><button class="article-clipboard" title="Copy to clipboard" data-toggle="tooltip" data-placement="top" data-clipboard-target="section[id^='tabpanel'][data-tab='ps'] pre"> | ||
<span class="glyphicon glyphicon-copy" aria-hidden="true"></span> | ||
<span class="article-clipboard__message done">Copied</span> | ||
</button> | ||
|
||
<pre><code class="lang-powershell"> | ||
|
||
function Get-TenantIdFromDomain { | ||
<# | ||
.SYNOPSIS | ||
Get the tenant ID for any Domain. | ||
|
||
.DESCRIPTION | ||
Will check and return the tenant ID for any domin, or return $false if no ID is found. | ||
|
||
.PARAMETER domain | ||
Any domain name, ex. domain.com | ||
|
||
.INPUTS | ||
domain name: domain.com | ||
|
||
.OUTPUTS | ||
String or boolean False. | ||
|
||
.EXAMPLE | ||
Get-TenantIdFromDomain domain.com | ||
Get-TenantIdFromDomain -domain domain.com | ||
"domain.com" | Get-TenantIdFromDomain | ||
|
||
.NOTES | ||
FileName: Get-TenantIdFromDomain.psm1 | ||
Author: Daniel Kåven | ||
Contact: @dkaaven | ||
Created: 2022-03-25 | ||
Updated: 2024-10-13 | ||
Version History: | ||
1.0.0 - (2022-03-25) Script created | ||
1.1.0 - (2024-06-20) Added check for missing domain | ||
1.2.0 - (2024-08-13) Added ability to get data from Pipeline | ||
|
||
#> | ||
|
||
param( | ||
[CmdletBinding()] | ||
[parameter( | ||
Mandatory = $true, | ||
Position = 0, | ||
HelpMessage = "The domain name of the target tenant.", | ||
ValueFromPipeline = $true, | ||
ValueFromPipelineByPropertyName = $true | ||
)] | ||
[String]$domain | ||
) | ||
|
||
# Check if tenant exists | ||
try { | ||
$request = Invoke-WebRequest -Uri https://login.windows.net/$domain/.well-known/openid-configuration | ||
} | ||
catch { | ||
if ($null -eq $request) { | ||
return $false | ||
} else { | ||
Write-Error $_ | ||
} | ||
} | ||
|
||
# Return tenant ID | ||
$data = ConvertFrom-Json $request.Content | ||
$result = $data.token_endpoint.split('/')[3] | ||
return $result | ||
} | ||
|
||
</code></pre> | ||
<div class="highlight-tool"> | ||
<p>Check out the <strong>PowerShell</strong> to learn more at: <a href="https://learn.microsoft.com/powershell">PowerShell Documentation | Microsoft Learn</a></p> | ||
</div> | ||
</section> | ||
<section id="tabpanel_CeZOj-G++Q_ps1" role="tabpanel" data-tab="ps1" aria-hidden="true" hidden="hidden"><button class="article-clipboard" title="Copy to clipboard" data-toggle="tooltip" data-placement="top" data-clipboard-target="section[id^='tabpanel'][data-tab='ps1'] pre"> | ||
<span class="glyphicon glyphicon-copy" aria-hidden="true"></span> | ||
<span class="article-clipboard__message done">Copied</span> | ||
</button> | ||
|
||
<pre><code class="lang-powershell"> | ||
function Get-TenantIdFromSubscriptionId { | ||
<# | ||
.SYNOPSIS | ||
Get the tenant ID from an Azure Subscription ID. | ||
.DESCRIPTION | ||
Will check and return the tenant ID for an Azure Subscription ID or return $false if no ID is found. | ||
Inspired from [Jos Lieben @ lieben.nu](https://www.lieben.nu/liebensraum/2020/08/get-tenant-id-using-azure-subscription-id/) | ||
|
||
.PARAMETER subscriptionId | ||
The Azure Subscription ID to check. | ||
|
||
.INPUTS | ||
Azure Subscription Id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | ||
|
||
.OUTPUTS | ||
String or boolean False. | ||
|
||
.EXAMPLE | ||
Get-TenantIdFromSubscriptionId xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | ||
Get-TenantIdFromSubscriptionId -subscriptionId xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | ||
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | Get-TenantIdFromSubscriptionId | ||
|
||
.NOTES | ||
FileName: Get-TenantIdFromSubscriptionId.psm1 | ||
Author: Daniel Kåven | ||
Contact: @DKaaven | ||
Created: 2024-08-06 | ||
Updated: 2024-08-06 | ||
Version history: | ||
1.0.0 - (2024-08-06) Script created | ||
#> | ||
param ( | ||
[CmdletBinding()] | ||
[Parameter( | ||
Mandatory = $true, | ||
Position = 0, | ||
HelpMessage = "The Azure Subscription ID", | ||
ValueFromPipeline = $true, | ||
ValueFromPipelineByPropertyName = $true | ||
)] | ||
[Alias("subId")] | ||
[String]$subscriptionId | ||
) | ||
# Check Subscription ID format | ||
$guidPattern = "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" | ||
if ($subscriptionId -notmatch $guidPattern) { | ||
Write-Error "$subscriptionId is not a valid Azure Subscription ID." | ||
return $false | ||
} | ||
$response = try {(Invoke-WebRequest -UseBasicParsing -Uri "https://management.azure.com/subscriptions/$($subscriptionId)?api-version=2015-01-01" -ErrorAction Stop).BaseResponse} catch { $_.Exception.Response } | ||
$stringHeader = $response.Headers.ToString() | ||
$tenantId = $stringHeader.SubString($stringHeader.IndexOf("login.windows.net")+18,36) | ||
|
||
# Check if it exist or return false | ||
if ($tenantId -match $guidPattern) { | ||
return $tenantId | ||
} | ||
else { | ||
return $false | ||
} | ||
|
||
} | ||
|
||
</code></pre> | ||
<div class="highlight-tool"> | ||
<p>Check out the <strong>PowerShell</strong> to learn more at: <a href="https://learn.microsoft.com/powershell">PowerShell Documentation | Microsoft Learn</a></p> | ||
</div> | ||
</section> | ||
</div> | ||
<h2 id="source-credit">Source Credit</h2> | ||
<p>Sample first appeared on <a href="https://github.com/dkaaven/M365-Scripts">https://github.com/dkaaven/M365-Scripts</a></p> | ||
<h2 id="contributors">Contributors</h2> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Author(s)</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td><a href="https://github.com/dkaaven">Daniel Kåven</a></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<h2 id="disclaimer">Disclaimer</h2> | ||
<p><strong>THESE SAMPLES ARE PROVIDED <em>AS IS</em> WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.</strong></p> | ||
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/aad-get-tenantid" aria-hidden="true"> | ||
</article> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<footer> | ||
<div class="grad-bottom"></div> | ||
<div class="footer"> | ||
<div class="container"> | ||
<span class="pull-right"> | ||
<a href="#top">Back to top</a> | ||
</span> | ||
<span>Script Samples<br>Generated by <strong><a href='https://dotnet.github.io/docfx' alt='Doc FX Website'>DocFX</a></strong> with <strong><a href='https://ovasquez.github.io/docfx-material' alt='DocFx Material Theme'>Material UI</a></strong></span> | ||
|
||
<!-- <img src="https://telemetry.sharepointpnp.com/@pnp.github.io/index/" alt="spacer"> --> | ||
</div> | ||
</div> | ||
</footer> </div> | ||
|
||
<script type="text/javascript" src="../styles/docfx.vendor.js"></script> | ||
<script type="text/javascript" src="../styles/docfx.js"></script> | ||
<script type="text/javascript" src="../styles/main.js"></script> | ||
|
||
<script type="text/javascript" src="../styles/clipboard.min.js"></script> | ||
<script type="text/javascript" src="../styles/isotope.pkgd.min.js"></script> | ||
<script type="text/javascript" src="../styles/loadsamples.js"></script> | ||
<script type="text/javascript" src="../styles/filtersamples.js"></script> | ||
|
||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
[ | ||
{ | ||
"name": "aad-get-tenantid", | ||
"source": "pnp", | ||
"title": "Get Tenant ID", | ||
"shortDescription": "These are 2 practical scripts to get Tenant ID from either a domain name or from a Subscriptionis ID.", | ||
"url": "https://pnp.github.io/script-samples/aad-get-tenantid/README.html", | ||
"longDescription": [ | ||
"" | ||
], | ||
"creationDateTime": "2024-10-14", | ||
"updateDateTime": "2024-10-14", | ||
"products": [ | ||
"Azure" | ||
], | ||
"metadata": [ | ||
{ | ||
"key": "POWERSHELL", | ||
"value": "7.2.0" | ||
} | ||
], | ||
"categories": [ | ||
"Report", | ||
"Security" | ||
], | ||
"tags": [ | ||
"<Cmdlets-Used>" | ||
], | ||
"thumbnails": [ | ||
{ | ||
"type": "image", | ||
"order": 100, | ||
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/aad-get-tenantid/assets/preview.png", | ||
"alt": "Preview of the sample AAD-Get-TenantID" | ||
} | ||
], | ||
"authors": [ | ||
{ | ||
"gitHubAccount": "dkaaven", | ||
"company": "", | ||
"pictureUrl": "https://github.com/dkaaven.png", | ||
"name": "Daniel Kåven" | ||
} | ||
], | ||
"references": [ | ||
|
||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.