From f30892a7651cc41e5cf080614e8fb6df7970a225 Mon Sep 17 00:00:00 2001 From: Swapnil Shrivastava Date: Mon, 13 Dec 2021 11:54:25 +0530 Subject: [PATCH 1/5] added cmdlets --- build/Build-Debug.ps1 | 4 +-- .../Get-PnPContentTypePublishingStatus.cs | 27 ++++++++++++++++++ .../ContentTypes/Publish-PnPContentType.cs | 28 +++++++++++++++++++ .../ContentTypes/Unpublish-PnPContentType.cs | 27 ++++++++++++++++++ 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 src/Commands/ContentTypes/Get-PnPContentTypePublishingStatus.cs create mode 100644 src/Commands/ContentTypes/Publish-PnPContentType.cs create mode 100644 src/Commands/ContentTypes/Unpublish-PnPContentType.cs diff --git a/build/Build-Debug.ps1 b/build/Build-Debug.ps1 index f7f0f9995..4e19efd6b 100644 --- a/build/Build-Debug.ps1 +++ b/build/Build-Debug.ps1 @@ -140,7 +140,7 @@ if ($LASTEXITCODE -eq 0) { else { $destinationFolder = "$documentsFolder/PowerShell/Modules/PnP.PowerShell" } - if ($PSVersionTable.PSVersion.Major -eq 5) { + if ($PSVersionTable.PSVersion.Major -eq 6) { Write-Host "Importing Framework version of assembly" Import-Module -Name "$destinationFolder/Framework/PnP.PowerShell.dll" -DisableNameChecking } @@ -168,7 +168,7 @@ if ($LASTEXITCODE -eq 0) { Author = 'Microsoft 365 Patterns and Practices' CompanyName = 'Microsoft 365 Patterns and Practices' CompatiblePSEditions = @(`"Core`",`"Desktop`") - PowerShellVersion = '5.1' + PowerShellVersion = '6.1' DotNetFrameworkVersion = '4.6.1' ProcessorArchitecture = 'None' FunctionsToExport = '*' diff --git a/src/Commands/ContentTypes/Get-PnPContentTypePublishingStatus.cs b/src/Commands/ContentTypes/Get-PnPContentTypePublishingStatus.cs new file mode 100644 index 000000000..311f121c6 --- /dev/null +++ b/src/Commands/ContentTypes/Get-PnPContentTypePublishingStatus.cs @@ -0,0 +1,27 @@ +using System.Management.Automation; +using Microsoft.SharePoint.Client; + +using PnP.PowerShell.Commands.Base.PipeBinds; + +namespace PnP.PowerShell.Commands.ContentTypes +{ + [Cmdlet(VerbsCommon.Get, "PnPContentType")] + public class GetContentTypePublishingStatus : PnPWebCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true)] + [ValidateNotNullOrEmpty] + public ContentType ContentTypeToUnpublish; + + protected override void ExecuteCmdlet() + { + Microsoft.SharePoint.Client.Site site = ClientContext.Site; + ClientContext.Load(site); + ClientContext.ExecuteQuery(); + var pub = new Microsoft.SharePoint.Client.Taxonomy.ContentTypeSync.ContentTypePublisher(ClientContext, site); + ClientContext.Load(pub); + ClientContext.ExecuteQuery(); + var isPublished = pub.IsPublished(ContentTypeToUnpublish); + WriteObject(isPublished); + } + } +} diff --git a/src/Commands/ContentTypes/Publish-PnPContentType.cs b/src/Commands/ContentTypes/Publish-PnPContentType.cs new file mode 100644 index 000000000..e5b38790f --- /dev/null +++ b/src/Commands/ContentTypes/Publish-PnPContentType.cs @@ -0,0 +1,28 @@ +using System.Management.Automation; +using Microsoft.SharePoint.Client; + +using PnP.PowerShell.Commands.Base.PipeBinds; + +namespace PnP.PowerShell.Commands.ContentTypes +{ + [Cmdlet(VerbsData.Publish, "PnPContentType")] + public class PublishContentType : PnPWebCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true)] + [ValidateNotNullOrEmpty] + public ContentType ContentTypeToPublish; + + protected override void ExecuteCmdlet() + { + Microsoft.SharePoint.Client.Site site = ClientContext.Site; + ClientContext.Load(site); + ClientContext.ExecuteQuery(); + var pub = new Microsoft.SharePoint.Client.Taxonomy.ContentTypeSync.ContentTypePublisher(ClientContext, site); + ClientContext.Load(pub); + ClientContext.ExecuteQuery(); + var republish = pub.IsPublished(ContentTypeToPublish); + pub.Publish(ContentTypeToPublish, republish); + ClientContext.ExecuteQuery(); + } + } +} diff --git a/src/Commands/ContentTypes/Unpublish-PnPContentType.cs b/src/Commands/ContentTypes/Unpublish-PnPContentType.cs new file mode 100644 index 000000000..fadadb1e1 --- /dev/null +++ b/src/Commands/ContentTypes/Unpublish-PnPContentType.cs @@ -0,0 +1,27 @@ +using System.Management.Automation; +using Microsoft.SharePoint.Client; + +using PnP.PowerShell.Commands.Base.PipeBinds; + +namespace PnP.PowerShell.Commands.ContentTypes +{ + [Cmdlet(VerbsData.Unpublish, "PnPContentType")] + public class UnpublishContentType : PnPWebCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true)] + [ValidateNotNullOrEmpty] + public ContentType ContentTypeToUnpublish; + + protected override void ExecuteCmdlet() + { + Microsoft.SharePoint.Client.Site site = ClientContext.Site; + ClientContext.Load(site); + ClientContext.ExecuteQuery(); + var pub = new Microsoft.SharePoint.Client.Taxonomy.ContentTypeSync.ContentTypePublisher(ClientContext, site); + ClientContext.Load(pub); + ClientContext.ExecuteQuery(); + pub.Unpublish(ContentTypeToUnpublish); + ClientContext.ExecuteQuery(); + } + } +} From c41039267f470cc90e50496390cf7d1076bd04ab Mon Sep 17 00:00:00 2001 From: Swapnil Shrivastava Date: Mon, 13 Dec 2021 12:13:58 +0530 Subject: [PATCH 2/5] Added tests --- .../Get-PnPContentTypePublishingStatus.cs | 4 +- .../ContentTypes/Publish-PnPContentType.cs | 6 +-- .../ContentTypes/Unpublish-PnPContentType.cs | 4 +- .../GetPnPContentTypePublishingStatusTests.cs | 38 +++++++++++++++++++ .../PublishPnPContentTypeTests.cs | 37 ++++++++++++++++++ .../UnpublishPnPContentTypeTests.cs | 38 +++++++++++++++++++ 6 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 src/Tests/ContentTypes/GetPnPContentTypePublishingStatusTests.cs create mode 100644 src/Tests/ContentTypes/PublishPnPContentTypeTests.cs create mode 100644 src/Tests/ContentTypes/UnpublishPnPContentTypeTests.cs diff --git a/src/Commands/ContentTypes/Get-PnPContentTypePublishingStatus.cs b/src/Commands/ContentTypes/Get-PnPContentTypePublishingStatus.cs index 311f121c6..e289a1413 100644 --- a/src/Commands/ContentTypes/Get-PnPContentTypePublishingStatus.cs +++ b/src/Commands/ContentTypes/Get-PnPContentTypePublishingStatus.cs @@ -10,7 +10,7 @@ public class GetContentTypePublishingStatus : PnPWebCmdlet { [Parameter(Mandatory = true, ValueFromPipeline = true)] [ValidateNotNullOrEmpty] - public ContentType ContentTypeToUnpublish; + public ContentType ContentType; protected override void ExecuteCmdlet() { @@ -20,7 +20,7 @@ protected override void ExecuteCmdlet() var pub = new Microsoft.SharePoint.Client.Taxonomy.ContentTypeSync.ContentTypePublisher(ClientContext, site); ClientContext.Load(pub); ClientContext.ExecuteQuery(); - var isPublished = pub.IsPublished(ContentTypeToUnpublish); + var isPublished = pub.IsPublished(ContentType); WriteObject(isPublished); } } diff --git a/src/Commands/ContentTypes/Publish-PnPContentType.cs b/src/Commands/ContentTypes/Publish-PnPContentType.cs index e5b38790f..6feae6992 100644 --- a/src/Commands/ContentTypes/Publish-PnPContentType.cs +++ b/src/Commands/ContentTypes/Publish-PnPContentType.cs @@ -10,7 +10,7 @@ public class PublishContentType : PnPWebCmdlet { [Parameter(Mandatory = true, ValueFromPipeline = true)] [ValidateNotNullOrEmpty] - public ContentType ContentTypeToPublish; + public ContentType ContentType; protected override void ExecuteCmdlet() { @@ -20,8 +20,8 @@ protected override void ExecuteCmdlet() var pub = new Microsoft.SharePoint.Client.Taxonomy.ContentTypeSync.ContentTypePublisher(ClientContext, site); ClientContext.Load(pub); ClientContext.ExecuteQuery(); - var republish = pub.IsPublished(ContentTypeToPublish); - pub.Publish(ContentTypeToPublish, republish); + var republish = pub.IsPublished(ContentType); + pub.Publish(ContentType, republish); ClientContext.ExecuteQuery(); } } diff --git a/src/Commands/ContentTypes/Unpublish-PnPContentType.cs b/src/Commands/ContentTypes/Unpublish-PnPContentType.cs index fadadb1e1..119a2024c 100644 --- a/src/Commands/ContentTypes/Unpublish-PnPContentType.cs +++ b/src/Commands/ContentTypes/Unpublish-PnPContentType.cs @@ -10,7 +10,7 @@ public class UnpublishContentType : PnPWebCmdlet { [Parameter(Mandatory = true, ValueFromPipeline = true)] [ValidateNotNullOrEmpty] - public ContentType ContentTypeToUnpublish; + public ContentType ContentType; protected override void ExecuteCmdlet() { @@ -20,7 +20,7 @@ protected override void ExecuteCmdlet() var pub = new Microsoft.SharePoint.Client.Taxonomy.ContentTypeSync.ContentTypePublisher(ClientContext, site); ClientContext.Load(pub); ClientContext.ExecuteQuery(); - pub.Unpublish(ContentTypeToUnpublish); + pub.Unpublish(ContentType); ClientContext.ExecuteQuery(); } } diff --git a/src/Tests/ContentTypes/GetPnPContentTypePublishingStatusTests.cs b/src/Tests/ContentTypes/GetPnPContentTypePublishingStatusTests.cs new file mode 100644 index 000000000..2fb18de16 --- /dev/null +++ b/src/Tests/ContentTypes/GetPnPContentTypePublishingStatusTests.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace PnP.PowerShell.Tests.ContentTypes +{ + [TestClass] + public class GetPnPContentTypePublishingStatusTests : PnPTest + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + #endregion + #region Scaffolded Cmdlet Tests + [TestMethod] + public void GetPnPContentTypePublishingStatusTest() + { + using (var scope = new PSTestScope(true)) + { + Microsoft.SharePoint.Client.Web web = ClientContext.Web; + var contentType = web.ContentTypes.GetById("0x0101"); + var results = scope.ExecuteCommand("Get-PnPContentTypePublishingStatus", + new CommandParameter("ContentType", contentType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/src/Tests/ContentTypes/PublishPnPContentTypeTests.cs b/src/Tests/ContentTypes/PublishPnPContentTypeTests.cs new file mode 100644 index 000000000..ae112a718 --- /dev/null +++ b/src/Tests/ContentTypes/PublishPnPContentTypeTests.cs @@ -0,0 +1,37 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace PnP.PowerShell.Tests.ContentTypes +{ + [TestClass] + public class PublishPnPContentTypeTests : PnPTest + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + #endregion + #region Scaffolded Cmdlet Tests + [TestMethod] + public void PublishPnPContentTypeTest() + { + using (var scope = new PSTestScope(true)) + { + Microsoft.SharePoint.Client.Web web = ClientContext.Web; + var contentType = web.ContentTypes.GetById("0x0101"); + var results = scope.ExecuteCommand("Publish-PnPContentType", + new CommandParameter("ContentType", contentType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file diff --git a/src/Tests/ContentTypes/UnpublishPnPContentTypeTests.cs b/src/Tests/ContentTypes/UnpublishPnPContentTypeTests.cs new file mode 100644 index 000000000..76331f118 --- /dev/null +++ b/src/Tests/ContentTypes/UnpublishPnPContentTypeTests.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Management.Automation.Runspaces; + +namespace PnP.PowerShell.Tests.ContentTypes +{ + [TestClass] + public class UnpublishPnPContentTypeTests : PnPTest + { + #region Test Setup/CleanUp + [ClassInitialize] + public static void Initialize(TestContext testContext) + { + // This runs on class level once before all tests run + //using (var ctx = TestCommon.CreateClientContext()) + //{ + //} + } + #endregion + #region Scaffolded Cmdlet Tests + [TestMethod] + public void UnpublishPnPContentTypeTest() + { + using (var scope = new PSTestScope(true)) + { + Microsoft.SharePoint.Client.Web web = ClientContext.Web; + var contentType = web.ContentTypes.GetById("0x0101"); + var results = scope.ExecuteCommand("Unpublish-PnPContentType", + new CommandParameter("ContentType", contentType)); + + Assert.IsNotNull(results); + } + } + #endregion + } +} + \ No newline at end of file From e002bcd56a0b2c628b97cecbdb9d74660124dba1 Mon Sep 17 00:00:00 2001 From: Swapnil Shrivastava Date: Thu, 3 Feb 2022 10:41:21 +0530 Subject: [PATCH 3/5] fixed build issues --- .../Get-PnPContentTypePublishingStatus.md | 68 +++++++++++++++++++ documentation/Publish-PnPContentType.md | 68 +++++++++++++++++++ documentation/Unpublish-PnPContentType.md | 68 +++++++++++++++++++ .../Get-PnPContentTypePublishingStatus.cs | 18 +++-- .../ContentTypes/Publish-PnPContentType.cs | 18 +++-- .../ContentTypes/Unpublish-PnPContentType.cs | 15 +++- .../GetPnPContentTypePublishingStatusTests.cs | 4 +- .../PublishPnPContentTypeTests.cs | 4 +- .../UnpublishPnPContentTypeTests.cs | 4 +- 9 files changed, 247 insertions(+), 20 deletions(-) create mode 100644 documentation/Get-PnPContentTypePublishingStatus.md create mode 100644 documentation/Publish-PnPContentType.md create mode 100644 documentation/Unpublish-PnPContentType.md diff --git a/documentation/Get-PnPContentTypePublishingStatus.md b/documentation/Get-PnPContentTypePublishingStatus.md new file mode 100644 index 000000000..3eed81578 --- /dev/null +++ b/documentation/Get-PnPContentTypePublishingStatus.md @@ -0,0 +1,68 @@ +--- +Module Name: PnP.PowerShell +schema: 2.0.0 +applicable: SharePoint Online +online version: https://pnp.github.io/powershell/cmdlets/Get-PnPContentTypePublishingStatus.html +external help file: PnP.PowerShell.dll-Help.xml +title: Get-PnPContentTypePublishingStatus +--- + +# Get-PnPContentTypePublishingStatus + +## SYNOPSIS + +**Required Permissions** + + * Fullcontrol permission on the content type hub site. + +Returns the publishing status of a content type present on content type hub site. + +## SYNTAX + +```powershell +Get-PnPContentTypePublishingStatus -ContentType [-Connection ] [] +``` + +## DESCRIPTION + +## EXAMPLES + +### EXAMPLE 1 +```powershell + Get-PnPContentTypePublishingStatus -ContentType 0x0101 +``` + +This will return `True` if content type is published in the content type hub site otherwise it will return `False`. +## PARAMETERS + +### -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 +``` + +### -ContentType +The content type object in the content type hub site for which the publishing status needs to be fetched. + +```yaml +Type: ContentType +Parameter Sets: (All) + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## RELATED LINKS + +[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) \ No newline at end of file diff --git a/documentation/Publish-PnPContentType.md b/documentation/Publish-PnPContentType.md new file mode 100644 index 000000000..e39dadae7 --- /dev/null +++ b/documentation/Publish-PnPContentType.md @@ -0,0 +1,68 @@ +--- +Module Name: PnP.PowerShell +schema: 2.0.0 +applicable: SharePoint Online +online version: https://pnp.github.io/powershell/cmdlets/Publish-PnPContentType.html +external help file: PnP.PowerShell.dll-Help.xml +title: Publish-PnPContentType +--- + +# Publish-PnPContentType + +## SYNOPSIS + +**Required Permissions** + + * Fullcontrol permission on the content type hub site. + +Publishes or republishes a content type present on content type hub site. + +## SYNTAX + +```powershell +Publish-PnPContentType -ContentType [-Connection ] [] +``` + +## DESCRIPTION + +## EXAMPLES + +### EXAMPLE 1 +```powershell + Publish-PnPContentType -ContentType 0x0101 +``` + +This will publish the content type with the given id. +## PARAMETERS + +### -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 +``` + +### -ContentType +The content type object in the content type hub site which is to be published. + +```yaml +Type: ContentType +Parameter Sets: (All) + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## RELATED LINKS + +[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) \ No newline at end of file diff --git a/documentation/Unpublish-PnPContentType.md b/documentation/Unpublish-PnPContentType.md new file mode 100644 index 000000000..91e2677cc --- /dev/null +++ b/documentation/Unpublish-PnPContentType.md @@ -0,0 +1,68 @@ +--- +Module Name: PnP.PowerShell +schema: 2.0.0 +applicable: SharePoint Online +online version: https://pnp.github.io/powershell/cmdlets/Unpublish-PnPContentType.html +external help file: PnP.PowerShell.dll-Help.xml +title: Unpublish-PnPContentType +--- + +# Unpublish-PnPContentType + +## SYNOPSIS + +**Required Permissions** + + * Fullcontrol permission on the content type hub site. + +Unpublishes a content type present on content type hub site. + +## SYNTAX + +```powershell +Unpublish-PnPContentType -ContentType [-Connection ] [] +``` + +## DESCRIPTION + +## EXAMPLES + +### EXAMPLE 1 +```powershell + Unpublish-PnPContentType -ContentType 0x0101 +``` + +This will unpublish the content type with the given id. +## PARAMETERS + +### -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 +``` + +### -ContentType +The content type object in the content type hub site which is to be unpublished. + +```yaml +Type: ContentType +Parameter Sets: (All) + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## RELATED LINKS + +[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) \ No newline at end of file diff --git a/src/Commands/ContentTypes/Get-PnPContentTypePublishingStatus.cs b/src/Commands/ContentTypes/Get-PnPContentTypePublishingStatus.cs index e289a1413..1d87db20b 100644 --- a/src/Commands/ContentTypes/Get-PnPContentTypePublishingStatus.cs +++ b/src/Commands/ContentTypes/Get-PnPContentTypePublishingStatus.cs @@ -1,3 +1,4 @@ +using System; using System.Management.Automation; using Microsoft.SharePoint.Client; @@ -5,12 +6,12 @@ namespace PnP.PowerShell.Commands.ContentTypes { - [Cmdlet(VerbsCommon.Get, "PnPContentType")] + [Cmdlet(VerbsCommon.Get, "PnPContentTypePublishingStatus")] public class GetContentTypePublishingStatus : PnPWebCmdlet { - [Parameter(Mandatory = true, ValueFromPipeline = true)] + [Parameter(Mandatory = false, Position = 0, ValueFromPipeline = true)] [ValidateNotNullOrEmpty] - public ContentType ContentType; + public ContentTypePipeBind ContentType; protected override void ExecuteCmdlet() { @@ -20,7 +21,16 @@ protected override void ExecuteCmdlet() var pub = new Microsoft.SharePoint.Client.Taxonomy.ContentTypeSync.ContentTypePublisher(ClientContext, site); ClientContext.Load(pub); ClientContext.ExecuteQuery(); - var isPublished = pub.IsPublished(ContentType); + var ct = ContentType.GetContentTypeOrError(this, nameof(ContentType), site.RootWeb); + + if (ct == null) + { + WriteError(new ErrorRecord(new Exception($"Invalid content type id."), "INVALIDCTID", ErrorCategory.InvalidArgument, ContentType)); + return; + } + + var isPublished = pub.IsPublished(ct); + ClientContext.ExecuteQuery(); WriteObject(isPublished); } } diff --git a/src/Commands/ContentTypes/Publish-PnPContentType.cs b/src/Commands/ContentTypes/Publish-PnPContentType.cs index 6feae6992..cb31f9d13 100644 --- a/src/Commands/ContentTypes/Publish-PnPContentType.cs +++ b/src/Commands/ContentTypes/Publish-PnPContentType.cs @@ -1,3 +1,4 @@ +using System; using System.Management.Automation; using Microsoft.SharePoint.Client; @@ -8,9 +9,9 @@ namespace PnP.PowerShell.Commands.ContentTypes [Cmdlet(VerbsData.Publish, "PnPContentType")] public class PublishContentType : PnPWebCmdlet { - [Parameter(Mandatory = true, ValueFromPipeline = true)] + [Parameter(Mandatory = false, Position = 0, ValueFromPipeline = true)] [ValidateNotNullOrEmpty] - public ContentType ContentType; + public ContentTypePipeBind ContentType; protected override void ExecuteCmdlet() { @@ -20,8 +21,17 @@ protected override void ExecuteCmdlet() var pub = new Microsoft.SharePoint.Client.Taxonomy.ContentTypeSync.ContentTypePublisher(ClientContext, site); ClientContext.Load(pub); ClientContext.ExecuteQuery(); - var republish = pub.IsPublished(ContentType); - pub.Publish(ContentType, republish); + var ct = ContentType.GetContentTypeOrError(this, nameof(ContentType), site.RootWeb); + + if (ct == null) + { + WriteError(new ErrorRecord(new Exception($"Invalid content type id."), "INVALIDCTID", ErrorCategory.InvalidArgument, ContentType)); + return; + } + + var republish = pub.IsPublished(ct); + ClientContext.ExecuteQuery(); + pub.Publish(ct, republish.Value); ClientContext.ExecuteQuery(); } } diff --git a/src/Commands/ContentTypes/Unpublish-PnPContentType.cs b/src/Commands/ContentTypes/Unpublish-PnPContentType.cs index 119a2024c..1a54ab096 100644 --- a/src/Commands/ContentTypes/Unpublish-PnPContentType.cs +++ b/src/Commands/ContentTypes/Unpublish-PnPContentType.cs @@ -1,3 +1,4 @@ +using System; using System.Management.Automation; using Microsoft.SharePoint.Client; @@ -8,9 +9,9 @@ namespace PnP.PowerShell.Commands.ContentTypes [Cmdlet(VerbsData.Unpublish, "PnPContentType")] public class UnpublishContentType : PnPWebCmdlet { - [Parameter(Mandatory = true, ValueFromPipeline = true)] + [Parameter(Mandatory = false, Position = 0, ValueFromPipeline = true)] [ValidateNotNullOrEmpty] - public ContentType ContentType; + public ContentTypePipeBind ContentType; protected override void ExecuteCmdlet() { @@ -20,7 +21,15 @@ protected override void ExecuteCmdlet() var pub = new Microsoft.SharePoint.Client.Taxonomy.ContentTypeSync.ContentTypePublisher(ClientContext, site); ClientContext.Load(pub); ClientContext.ExecuteQuery(); - pub.Unpublish(ContentType); + var ct = ContentType.GetContentTypeOrError(this, nameof(ContentType), site.RootWeb); + + if (ct == null) + { + WriteError(new ErrorRecord(new Exception($"Invalid content type id."), "INVALIDCTID", ErrorCategory.InvalidArgument, ContentType)); + return; + } + + pub.Unpublish(ct); ClientContext.ExecuteQuery(); } } diff --git a/src/Tests/ContentTypes/GetPnPContentTypePublishingStatusTests.cs b/src/Tests/ContentTypes/GetPnPContentTypePublishingStatusTests.cs index 2fb18de16..987cafa98 100644 --- a/src/Tests/ContentTypes/GetPnPContentTypePublishingStatusTests.cs +++ b/src/Tests/ContentTypes/GetPnPContentTypePublishingStatusTests.cs @@ -24,10 +24,8 @@ public void GetPnPContentTypePublishingStatusTest() { using (var scope = new PSTestScope(true)) { - Microsoft.SharePoint.Client.Web web = ClientContext.Web; - var contentType = web.ContentTypes.GetById("0x0101"); var results = scope.ExecuteCommand("Get-PnPContentTypePublishingStatus", - new CommandParameter("ContentType", contentType)); + new CommandParameter("ContentType", "0x0101")); Assert.IsNotNull(results); } diff --git a/src/Tests/ContentTypes/PublishPnPContentTypeTests.cs b/src/Tests/ContentTypes/PublishPnPContentTypeTests.cs index ae112a718..bc21344cd 100644 --- a/src/Tests/ContentTypes/PublishPnPContentTypeTests.cs +++ b/src/Tests/ContentTypes/PublishPnPContentTypeTests.cs @@ -23,10 +23,8 @@ public void PublishPnPContentTypeTest() { using (var scope = new PSTestScope(true)) { - Microsoft.SharePoint.Client.Web web = ClientContext.Web; - var contentType = web.ContentTypes.GetById("0x0101"); var results = scope.ExecuteCommand("Publish-PnPContentType", - new CommandParameter("ContentType", contentType)); + new CommandParameter("ContentType", "0x0101")); Assert.IsNotNull(results); } diff --git a/src/Tests/ContentTypes/UnpublishPnPContentTypeTests.cs b/src/Tests/ContentTypes/UnpublishPnPContentTypeTests.cs index 76331f118..4ef8626ee 100644 --- a/src/Tests/ContentTypes/UnpublishPnPContentTypeTests.cs +++ b/src/Tests/ContentTypes/UnpublishPnPContentTypeTests.cs @@ -24,10 +24,8 @@ public void UnpublishPnPContentTypeTest() { using (var scope = new PSTestScope(true)) { - Microsoft.SharePoint.Client.Web web = ClientContext.Web; - var contentType = web.ContentTypes.GetById("0x0101"); var results = scope.ExecuteCommand("Unpublish-PnPContentType", - new CommandParameter("ContentType", contentType)); + new CommandParameter("ContentType", "0x0101")); Assert.IsNotNull(results); } From bd830a51286ebb5b6b09808dbfc456f5cfa9e0e8 Mon Sep 17 00:00:00 2001 From: Swapnil Shrivastava Date: Thu, 3 Feb 2022 10:43:44 +0530 Subject: [PATCH 4/5] Update Build-Debug.ps1 --- build/Build-Debug.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/Build-Debug.ps1 b/build/Build-Debug.ps1 index 26dd3d171..800859d09 100644 --- a/build/Build-Debug.ps1 +++ b/build/Build-Debug.ps1 @@ -139,7 +139,7 @@ if ($LASTEXITCODE -eq 0) { else { $destinationFolder = "$documentsFolder/PowerShell/Modules/PnP.PowerShell" } - if ($PSVersionTable.PSVersion.Major -eq 6) { + if ($PSVersionTable.PSVersion.Major -eq 5) { Write-Host "Importing Framework version of assembly" Import-Module -Name "$destinationFolder/Framework/PnP.PowerShell.dll" -DisableNameChecking } @@ -167,7 +167,7 @@ if ($LASTEXITCODE -eq 0) { Author = 'Microsoft 365 Patterns and Practices' CompanyName = 'Microsoft 365 Patterns and Practices' CompatiblePSEditions = @(`"Core`",`"Desktop`") - PowerShellVersion = '6.1' + PowerShellVersion = '5.1' DotNetFrameworkVersion = '4.6.1' ProcessorArchitecture = 'None' FunctionsToExport = '*' From 984257c552549021e1854cf574324f6de952d095 Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Thu, 3 Feb 2022 11:45:26 +0100 Subject: [PATCH 5/5] Adding changelog entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf83fcf35..88fc1fff1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added support to add multiple owners and members in `New-PnPTeamsTeam` cmdlet [#1241](https://github.com/pnp/powershell/pull/1241) - Added the ability to set the title of a new modern page in SharePoint Online using `Add-PnPPage` to be different from its filename by using `-Title` - Added `Get-PnPTeamsPrimaryChannel` to get the primary Teams channel, general, of a Team [#1572](https://github.com/pnp/powershell/pull/1572) +- Added `Publish\Unpublish-PnPContentType` to allow for content types to be published or unpublished on hub sites [#1597](https://github.com/pnp/powershell/pull/1597) +- Added `Get-PnPContentTypePublishingStatus` to get te current publication state of a content type in the content type hub site [#1597](https://github.com/pnp/powershell/pull/1597) ### Changed @@ -52,6 +54,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Contributors +- [swapnil1993] - Hugo Bernier [hugoabernier] - brenle - Johan Brännmar [brannmar]