diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e552f746..14c758771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Added - Added `-Wait` and `-Verbose` optional paramarers to `New-PnPUPABulkImportJob` [#1752](https://github.com/pnp/powershell/pull/1752) +- Added the ability to retrieve site collection information by its Id using `Get-PnPTenantSite -Identity ` [#1766](https://github.com/pnp/powershell/pull/1766) - Added `ResourceBehaviorOptions` option in `New-PnPMicrosoft365Group` cmdlet to set `ResourceBehaviorOptions` while provisioning a Microsoft 365 Group. [#1774](https://github.com/pnp/powershell/pull/1774) - Added `Add-PnPTeamsChannelUser` which allows members and owners to be added to private channels in Teams [#1735](https://github.com/pnp/powershell/pull/1735) - Added `ExcludeVisualPromotedResults` parameter to `Get-PnPSearchConfiguration` which excludes promoted results [#1750](https://github.com/pnp/powershell/pull/1750) diff --git a/documentation/Get-PnPTenantSite.md b/documentation/Get-PnPTenantSite.md index 9a9a7f66d..c5752083b 100644 --- a/documentation/Get-PnPTenantSite.md +++ b/documentation/Get-PnPTenantSite.md @@ -15,7 +15,7 @@ online version: https://pnp.github.io/powershell/cmdlets/Get-PnPTenantSite.html * SharePoint: Access to the SharePoint Tenant Administration site -Retrieve site information. +Retrieves site collection information ## SYNTAX @@ -32,7 +32,7 @@ Get-PnPTenantSite [-Template ] [-Detailed] [-IncludeOneDriveSites] [-Gro ``` ## DESCRIPTION -Use this cmdlet to retrieve site information from your tenant administration. +This cmdlet allows for retrieval of site collection information through the SharePoint Online tenant site. It requires having SharePoint Online administrator access. ## EXAMPLES @@ -41,56 +41,63 @@ Use this cmdlet to retrieve site information from your tenant administration. Get-PnPTenantSite ``` -Returns all site collections +Returns all site collections except the OneDrive for Business sites with basic information on them ### EXAMPLE 2 ```powershell -Get-PnPTenantSite -Identity "http://tenant.sharepoint.com/sites/projects" +Get-PnPTenantSite -Detailed ``` -Returns information about the project site +Returns all site collections except the OneDrive for Business sites with the full details on them ### EXAMPLE 3 ```powershell -Get-PnPTenantSite -Detailed +Get-PnPTenantSite -IncludeOneDriveSites ``` -Returns all sites with the full details of these sites +Returns all site collections including all OneDrive for Business sites ### EXAMPLE 4 ```powershell -Get-PnPTenantSite -IncludeOneDriveSites +Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'" ``` -Returns all sites including all OneDrive for Business sites +Returns only OneDrive for Business site collections ### EXAMPLE 5 ```powershell -Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'" +Get-PnPTenantSite -Identity "http://tenant.sharepoint.com/sites/projects" ``` -Returns all OneDrive for Business sites +Returns information of the site collection with the provided url ### EXAMPLE 6 ```powershell -Get-PnPTenantSite -Template SITEPAGEPUBLISHING#0 +Get-PnPTenantSite -Identity 7e8a6f56-92fe-4b22-9364-41799e579e8a ``` -Returns all Communication sites +Returns information of the site collection with the provided Id ### EXAMPLE 7 ```powershell -Get-PnPTenantSite -Filter "Url -like 'sales'" +Get-PnPTenantSite -Template SITEPAGEPUBLISHING#0 ``` -Returns all sites including 'sales' in the url +Returns all Communication site collections ### EXAMPLE 8 ```powershell +Get-PnPTenantSite -Filter "Url -like 'sales'" +``` + +Returns all site collections having 'sales' in their url + +### EXAMPLE 9 +```powershell Get-PnPTenantSite -GroupIdDefined $true ``` -Returns all sites which have an underlying Microsoft 365 Group +Returns all site collections which have an underlying Microsoft 365 Group ## PARAMETERS @@ -137,7 +144,7 @@ Accept wildcard characters: False ``` ### -Filter -Specifies the script block of the server-side filter to apply. See https://technet.microsoft.com/en-us/library/fp161380.aspx +Specifies the script block of the server-side filter to apply. See https://docs.microsoft.com/powershell/module/sharepoint-online/get-sposite?view=sharepoint-ps#:~:text=SharePoint%20Online-,%2DFilter,-Specifies%20the%20script. ```yaml Type: String @@ -193,7 +200,7 @@ Accept wildcard characters: False ``` ### -Identity -The URL of the site +The URL or Id of the site collection. Requesting a site collection by its Id only works for modern SharePoint Online site collections. ```yaml Type: String diff --git a/src/Commands/Admin/GetTenantSite.cs b/src/Commands/Admin/GetTenantSite.cs index d8401edfd..668cef586 100644 --- a/src/Commands/Admin/GetTenantSite.cs +++ b/src/Commands/Admin/GetTenantSite.cs @@ -3,7 +3,6 @@ using System.Management.Automation; using Microsoft.Online.SharePoint.TenantAdministration; using Microsoft.SharePoint.Client; - using PnP.PowerShell.Commands.Base; using PnP.PowerShell.Commands.Enums; using System.Collections.Generic; @@ -45,9 +44,18 @@ protected override void ExecuteCmdlet() ClientContext.ExecuteQueryRetry(); if (ParameterSpecified(nameof(Identity))) { - var siteProperties = Tenant.GetSitePropertiesByUrl(Identity.Url, Detailed); - ClientContext.Load(siteProperties); - ClientContext.ExecuteQueryRetry(); + SiteProperties siteProperties; + if(Identity.Id.HasValue) + { + siteProperties = Tenant.GetSitePropertiesById(Identity.Id.Value, Detailed); + if(siteProperties == null) return; + } + else + { + siteProperties = Tenant.GetSitePropertiesByUrl(Identity.Url, Detailed); + ClientContext.Load(siteProperties); + ClientContext.ExecuteQueryRetry(); + } Model.SPOSite site = null; if (ParameterSpecified(nameof(DisableSharingForNonOwnersStatus))) { diff --git a/src/Commands/Base/PipeBinds/SPOSitePipeBind.cs b/src/Commands/Base/PipeBinds/SPOSitePipeBind.cs index 29dd788d2..e56f1f652 100644 --- a/src/Commands/Base/PipeBinds/SPOSitePipeBind.cs +++ b/src/Commands/Base/PipeBinds/SPOSitePipeBind.cs @@ -7,17 +7,27 @@ namespace PnP.PowerShell.Commands.Base.PipeBinds public class SPOSitePipeBind { private string _url; + private Guid? _id; public string Url => _url; - public SPOSitePipeBind(string url) + public Guid? Id => _id; + + public SPOSitePipeBind(string identity) { - _url = url?.TrimEnd(new char[] { '/' }); + if(Guid.TryParse(identity, out Guid id)) + { + _id = id; + } + else + { + _url = identity?.TrimEnd('/'); + } } public SPOSitePipeBind(Uri uri) { - _url = uri.AbsoluteUri?.TrimEnd(new char[] { '/' }); + _url = uri.AbsoluteUri?.TrimEnd('/'); } public SPOSitePipeBind(SPOSite site) @@ -26,7 +36,7 @@ public SPOSitePipeBind(SPOSite site) { throw new PSArgumentException("Site Url must be specified"); } - _url = site.Url?.TrimEnd(new char[] { '/' }); + _url = site.Url?.TrimEnd('/'); } public SPOSitePipeBind(Model.SPODeletedSite site) @@ -35,7 +45,7 @@ public SPOSitePipeBind(Model.SPODeletedSite site) { throw new PSArgumentException("Site Url must be specified"); } - _url = site.Url?.TrimEnd(new char[] { '/' }); + _url = site.Url?.TrimEnd('/'); } } } \ No newline at end of file