Skip to content

Commit

Permalink
Merge pull request #1678 from swapnil1993/dev
Browse files Browse the repository at this point in the history
Added pnp cmdlet for getting compatible content types from ct hub
  • Loading branch information
KoenZomers authored Mar 13, 2022
2 parents 0d6de81 + 01bf280 commit adcee75
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `-AsMemoryStream` option to `Get-PnPFile` to allow for downloading of a file from SharePoint Online in memory for further processing [#1638](https://github.com/pnp/powershell/pull/1638)
- Added `-Stream` option to `Read-PnPSiteTemplate` to allow for processing on a PnP Provisioning Template coming from memory [#1638](https://github.com/pnp/powershell/pull/1638)
- Added `-Force` option to `Set-PnPTenant` to allow skipping the confirmation question for certain other parameters like `SignInAccelerationDomain,EnableGuestSignInAcceleration,BccExternalSharingInvitations,OrphanedPersonalSitesRetentionPeriod,OneDriveForGuestsEnabled,AllowDownloadingNonWebViewableFiles`.
- Added `Get-PnPCompatibleHubContentTypes` which allows the list of content types present in the content type hub site that can be added to the root web or a list on a target site to be returned [#1678](https://github.com/pnp/powershell/pull/1678)

### Changed

Expand Down
90 changes: 90 additions & 0 deletions documentation/Get-PnPCompatibleHubContentTypes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
Module Name: PnP.PowerShell
schema: 2.0.0
applicable: SharePoint Online
online version: https://pnp.github.io/powershell/cmdlets/Add-PnPContentTypesFromContentTypeHub.html
external help file: PnP.PowerShell.dll-Help.xml
title: Get-PnPCompatibleHubContentTypes
---

# Get-PnPCompatibleHubContentTypes

## SYNOPSIS

**Required Permissions**

* ViewPages permission on the current web.

Returns the list of content types present in content type hub site that can be added to the root web or a list on a target site.

## SYNTAX

```powershell
Get-PnPCompatibleHubContentTypes -WebUrl <String> [-ListUrl <String>] [-Connection <PnPConnection>] [<CommonParameters>]
```

## DESCRIPTION

## EXAMPLES

### EXAMPLE 1
```powershell
Get-PnPCompatibleHubContentTypes -WebUrl 'https://contoso.sharepoint.com/web1'
```

This will return the list of content types present in content type hub site that can be added to the root web of the site to which the provided web belongs.

### EXAMPLE 2
```powershell
Get-PnPCompatibleHubContentTypes -WebUrl 'https://contoso.sharepoint.com/web1' -ListUrl 'https://contoso.sharepoint.com/web1/Shared Documents'
```

This will return the list of content types present in content type hub site that can be added to the provided list.

## PARAMETERS

### -WebUrl
The full URL of the web for which compatible content types need to be fetched. In case of a list this should be the url of the web which contains the given list. I.e. 'https://contoso.sharepoint.com/web1'

```yaml
Type: String
Parameter Sets: (All)

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -ListUrl
The full URL to the list for which compatible content types need to be fetched, i.e. 'https://contoso.sharepoint.com/web1/Shared Documents'
```yaml
Type: String
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Connection
Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.
```yaml
Type: PnPConnection
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)
28 changes: 28 additions & 0 deletions src/Commands/ContentTypes/GetCompatibleHubContentTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Management.Automation;
using Microsoft.SharePoint.Client;

namespace PnP.PowerShell.Commands.ContentTypes
{
[Cmdlet(VerbsCommon.Get, "PnPCompatibleHubContentTypes")]
public class GetCompatibleHubContentTypes : PnPWebCmdlet
{
[Parameter(Mandatory = true)]
[ValidateNotNullOrEmpty]
public string WebUrl;

[Parameter(Mandatory = false)]
public string ListUrl;

protected override void ExecuteCmdlet()
{
var subscriber = new Microsoft.SharePoint.Client.Taxonomy.ContentTypeSync.ContentTypeSubscriber(ClientContext);
ClientContext.Load(subscriber);
ClientContext.ExecuteQueryRetry();

var results = subscriber.GetCompatibleHubContentTypes(WebUrl, ListUrl);
ClientContext.ExecuteQueryRetry();

WriteObject(results, true);
}
}
}

0 comments on commit adcee75

Please sign in to comment.