Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added retrieving site collection information by its Id using Get-PnPTenantSite #1766

Merged
merged 4 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <id>` [#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)
Expand Down
43 changes: 25 additions & 18 deletions documentation/Get-PnPTenantSite.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -32,7 +32,7 @@ Get-PnPTenantSite [-Template <string>] [-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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions src/Commands/Admin/GetTenantSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)))
{
Expand Down
20 changes: 15 additions & 5 deletions src/Commands/Base/PipeBinds/SPOSitePipeBind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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('/');
}
}
}