-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3414 from NishkalankBezawada/New-Command-Get-Tena…
…nt-Info [New Feature] - Get-PnPTenantInfo - to get tenant info of any tenant
- Loading branch information
Showing
4 changed files
with
226 additions
and
0 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
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,126 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
title: Get-PnPTenantInfo | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPTenantInfo.html | ||
--- | ||
|
||
# Get-PnPTenantInfo | ||
|
||
## SYNOPSIS | ||
Gets information about any tenant | ||
|
||
## SYNTAX | ||
|
||
### Current Tenant (default) | ||
```powershell | ||
Get-PnPTenantInfo [-Verbose] | ||
``` | ||
|
||
### By TenantId | ||
```powershell | ||
Get-PnPTenantInfo -TenantId <String> [-Verbose] | ||
``` | ||
|
||
### By Domain Name | ||
```powershell | ||
Get-PnPTenantInfo -DomainName <String> [-Verbose] | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
Gets the tenantId, federation brand name, company name and default domain name regarding a specific tenant. If no Domain name or Tenant id is specified, it returns the Tenant Info of the currently connected to tenant. | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
```powershell | ||
Get-PnPTenantInfo -TenantId "e65b162c-6f87-4eb1-a24e-1b37d3504663" | ||
``` | ||
|
||
Returns the tenant information of the specified TenantId. | ||
|
||
### EXAMPLE 2 | ||
```powershell | ||
Get-PnPTenantInfo -DomainName "contoso.com" | ||
``` | ||
|
||
Returns the Tenant Information for the tenant connected to the domain contoso.com. | ||
|
||
### EXAMPLE 3 | ||
```powershell | ||
Get-PnPTenantInfo | ||
``` | ||
|
||
Returns Tenant Information of the currently connected to tenant. | ||
|
||
### EXAMPLE 4 | ||
```powershell | ||
Get-PnPTenantInfo -CurrentTenant | ||
``` | ||
|
||
Returns Tenant Information of the currently connected to tenant. | ||
|
||
## PARAMETERS | ||
|
||
### -CurrentTenant | ||
Gets the Tenant Information of the currently connected to tenant. | ||
|
||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: GETINFOOFCURRENTTENANT | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -DomainName | ||
The Domain name of the tenant to lookup. You can use the onmicrosoft.com domain name such as "contoso.onmicrosoft.com" or use any domain that is connected to the tenant, i.e. "contoso.com". | ||
```yaml | ||
Type: String | ||
Parameter Sets: GETINFOBYTDOMAINNAME | ||
|
||
Required: False | ||
Position: Named | ||
Default value: Production | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -TenantId | ||
The id of the tenant to retrieve the information about | ||
```yaml | ||
Type: String | ||
Parameter Sets: GETINFOBYTENANTID | ||
|
||
Required: true | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -Verbose | ||
When provided, additional debug statements will be shown while executing the cmdlet. | ||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
## RELATED LINKS | ||
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) |
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,69 @@ | ||
using Microsoft.SharePoint.Client; | ||
using PnP.PowerShell.Commands.Base; | ||
using PnP.PowerShell.Commands.Utilities.REST; | ||
using System; | ||
using System.Management.Automation; | ||
|
||
namespace PnP.PowerShell.Commands.Admin | ||
{ | ||
[Cmdlet(VerbsCommon.Get, "PnPTenantInfo")] | ||
[OutputType(typeof(Model.TenantInfo))] | ||
public class GetTenantInfo : PnPAdminCmdlet | ||
{ | ||
private const string GETINFOBYTDOMAINNAME = "By Domain Name"; | ||
private const string GETINFOBYTENANTID = "By TenantId"; | ||
private const string GETINFOOFCURRENTTENANT = "Current Tenant"; | ||
|
||
[Parameter(Mandatory = false, ParameterSetName = GETINFOOFCURRENTTENANT)] | ||
public SwitchParameter CurrentTenant; | ||
|
||
[Parameter(Mandatory = true, ParameterSetName = GETINFOBYTDOMAINNAME)] | ||
public string DomainName; | ||
|
||
[Parameter(Mandatory = true, ParameterSetName = GETINFOBYTENANTID)] | ||
public string TenantId; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
if ((ParameterSetName == GETINFOBYTDOMAINNAME && TenantId != null) || (ParameterSetName == GETINFOBYTENANTID && DomainName != null)) | ||
{ | ||
throw new PSArgumentException("Specify either DomainName or TenantId, but not both."); | ||
} | ||
|
||
WriteVerbose("Acquiring access token for Microsoft Graph to look up Tenant"); | ||
var graphAccessToken = TokenHandler.GetAccessToken(this, $"https://{Connection.GraphEndPoint}/.default", Connection); | ||
var requestUrl = BuildRequestUrl(); | ||
|
||
WriteVerbose($"Making call to {requestUrl} to request tenant information"); | ||
var results = RestHelper.GetAsync<Model.TenantInfo>(Connection.HttpClient, requestUrl, graphAccessToken).GetAwaiter().GetResult(); | ||
WriteObject(results, true); | ||
} | ||
|
||
private string BuildRequestUrl() | ||
{ | ||
var baseUrl = $"https://{Connection.GraphEndPoint}/v1.0/tenantRelationships/"; | ||
var query = string.Empty; | ||
switch (ParameterSetName) | ||
{ | ||
case GETINFOBYTDOMAINNAME: | ||
query = $"microsoft.graph.findTenantInformationByDomainName(domainName='{DomainName}')"; | ||
break; | ||
case GETINFOBYTENANTID: | ||
query = $"microsoft.graph.findTenantInformationByTenantId(tenantId='{TenantId}')"; | ||
break; | ||
case GETINFOOFCURRENTTENANT: | ||
if (Connection != null) | ||
{ | ||
string tenantId = TenantExtensions.GetTenantIdByUrl(Connection.Url, Connection.AzureEnvironment).ToString(); | ||
query = $"microsoft.graph.findTenantInformationByTenantId(tenantId='{tenantId}')"; | ||
} | ||
else | ||
{ | ||
throw new InvalidOperationException($"The current connection holds no SharePoint context. Please use one of the Connect-PnPOnline commands which uses the -Url argument to connect."); | ||
} | ||
break; | ||
} | ||
return baseUrl + query; | ||
} | ||
} | ||
} |
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,30 @@ | ||
using System; | ||
|
||
namespace PnP.PowerShell.Commands.Model | ||
{ | ||
/// <summary> | ||
/// Contains information regarding a tenant | ||
/// </summary> | ||
public class TenantInfo | ||
{ | ||
/// <summary> | ||
/// Unique identifier of the tenant | ||
/// </summary> | ||
public Guid? TenantId { get; set; } | ||
|
||
/// <summary> | ||
/// The name of the string value shown to users when signing in to Entra ID | ||
/// </summary> | ||
public string FederationBrandName { get; set; } | ||
|
||
/// <summary> | ||
/// The company name shown in places such as the admin portal | ||
/// </summary> | ||
public string DisplayName { get; set; } | ||
|
||
/// <summary> | ||
/// The default domain name set on the tenant | ||
/// </summary> | ||
public string DefaultDomainName { get; set; } | ||
} | ||
} |