From 6c2a81248ef282c5cd196e00e54c7e67d616ccbb Mon Sep 17 00:00:00 2001 From: reshmee011 Date: Mon, 1 May 2023 07:03:08 +0100 Subject: [PATCH 1/4] New cmdlet to add script safe domain --- documentation/Add-PnPScriptSafeDomain.md | 65 +++++++++++++++++++ .../Site/AddScriptSafeDomainEntityData.cs | 42 ++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 documentation/Add-PnPScriptSafeDomain.md create mode 100644 src/Commands/Site/AddScriptSafeDomainEntityData.cs diff --git a/documentation/Add-PnPScriptSafeDomain.md b/documentation/Add-PnPScriptSafeDomain.md new file mode 100644 index 000000000..8f28bb970 --- /dev/null +++ b/documentation/Add-PnPScriptSafeDomain.md @@ -0,0 +1,65 @@ +--- +Module Name: PnP.PowerShell +schema: 2.0.0 +applicable: SharePoint Online +online version: https://pnp.github.io/powershell/cmdlets/Add-PnPScriptSafeDomain.html +external help file: PnP.PowerShell.dll-Help.xml +title: Add-PnPPnPScriptSafeDomain +--- + +# Add-PnPPnPScriptSafeDomain + +## SYNOPSIS +Adds a script safe domain to the site collection in the current context + +## SYNTAX + +```powershell +Add-PnPScriptSafeDomain -DomainName [-Connection ] +``` + +## DESCRIPTION +This command adds a script safe domain to the site collection in the current context. It does not replace or remove existing script safe domains. + +## EXAMPLES + +### EXAMPLE 1 +```powershell +Add-PnPRoleDefinition -DomainName "contoso.com" +``` + +Creates additional script safe domains. + +### -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 +``` + +### -DomainName +Name of the new script safe domain name. + +```yaml +Type: String +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) + + diff --git a/src/Commands/Site/AddScriptSafeDomainEntityData.cs b/src/Commands/Site/AddScriptSafeDomainEntityData.cs new file mode 100644 index 000000000..2d88ed6fd --- /dev/null +++ b/src/Commands/Site/AddScriptSafeDomainEntityData.cs @@ -0,0 +1,42 @@ +using Microsoft.SharePoint.Client; + +using PnP.PowerShell.Commands.Base.PipeBinds; + +using System.Management.Automation; + +namespace PnP.PowerShell.Commands.Site +{ + [Cmdlet(VerbsCommon.Add, "PnPScriptSafeDomain")] + [OutputType(typeof(ScriptSafeDomain))] + public class AddScriptSafeDomain : PnPSharePointCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true)] + public string DomainName; + protected override void ExecuteCmdlet() + { + // Validate user inputs + ScriptSafeDomain safeDomain = null; + try + { + safeDomain = ClientContext.Site.CustomScriptSafeDomains.GetByDomainName(DomainName); + ClientContext.Load(safeDomain); + ClientContext.ExecuteQueryRetry(); + } + catch { } + if (safeDomain.ServerObjectIsNull == null) + { + var spSafeDomain = new ScriptSafeDomainEntityData(); + spSafeDomain.DomainName = DomainName; + + safeDomain = ClientContext.Site.CustomScriptSafeDomains.Create(spSafeDomain); + ClientContext.Load(safeDomain); + ClientContext.ExecuteQueryRetry(); + WriteObject(safeDomain); + } + else + { + WriteWarning($"Unable to add Domain Name as there is an existing domain name with the same name. Will be skipped."); + } + } + } +} From 2c7cf0924d25690868d6d707c794202639c8b46f Mon Sep 17 00:00:00 2001 From: reshmee011 Date: Wed, 3 May 2023 15:18:34 +0100 Subject: [PATCH 2/4] Merge ScriptSafeDomain into SetSite --- documentation/Add-PnPScriptSafeDomain.md | 65 ------------------- .../Site/AddScriptSafeDomainEntityData.cs | 42 ------------ src/Commands/Site/SetSite.cs | 28 ++++++-- 3 files changed, 23 insertions(+), 112 deletions(-) delete mode 100644 documentation/Add-PnPScriptSafeDomain.md delete mode 100644 src/Commands/Site/AddScriptSafeDomainEntityData.cs diff --git a/documentation/Add-PnPScriptSafeDomain.md b/documentation/Add-PnPScriptSafeDomain.md deleted file mode 100644 index 8f28bb970..000000000 --- a/documentation/Add-PnPScriptSafeDomain.md +++ /dev/null @@ -1,65 +0,0 @@ ---- -Module Name: PnP.PowerShell -schema: 2.0.0 -applicable: SharePoint Online -online version: https://pnp.github.io/powershell/cmdlets/Add-PnPScriptSafeDomain.html -external help file: PnP.PowerShell.dll-Help.xml -title: Add-PnPPnPScriptSafeDomain ---- - -# Add-PnPPnPScriptSafeDomain - -## SYNOPSIS -Adds a script safe domain to the site collection in the current context - -## SYNTAX - -```powershell -Add-PnPScriptSafeDomain -DomainName [-Connection ] -``` - -## DESCRIPTION -This command adds a script safe domain to the site collection in the current context. It does not replace or remove existing script safe domains. - -## EXAMPLES - -### EXAMPLE 1 -```powershell -Add-PnPRoleDefinition -DomainName "contoso.com" -``` - -Creates additional script safe domains. - -### -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 -``` - -### -DomainName -Name of the new script safe domain name. - -```yaml -Type: String -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) - - diff --git a/src/Commands/Site/AddScriptSafeDomainEntityData.cs b/src/Commands/Site/AddScriptSafeDomainEntityData.cs deleted file mode 100644 index 2d88ed6fd..000000000 --- a/src/Commands/Site/AddScriptSafeDomainEntityData.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Microsoft.SharePoint.Client; - -using PnP.PowerShell.Commands.Base.PipeBinds; - -using System.Management.Automation; - -namespace PnP.PowerShell.Commands.Site -{ - [Cmdlet(VerbsCommon.Add, "PnPScriptSafeDomain")] - [OutputType(typeof(ScriptSafeDomain))] - public class AddScriptSafeDomain : PnPSharePointCmdlet - { - [Parameter(Mandatory = true, ValueFromPipeline = true)] - public string DomainName; - protected override void ExecuteCmdlet() - { - // Validate user inputs - ScriptSafeDomain safeDomain = null; - try - { - safeDomain = ClientContext.Site.CustomScriptSafeDomains.GetByDomainName(DomainName); - ClientContext.Load(safeDomain); - ClientContext.ExecuteQueryRetry(); - } - catch { } - if (safeDomain.ServerObjectIsNull == null) - { - var spSafeDomain = new ScriptSafeDomainEntityData(); - spSafeDomain.DomainName = DomainName; - - safeDomain = ClientContext.Site.CustomScriptSafeDomains.Create(spSafeDomain); - ClientContext.Load(safeDomain); - ClientContext.ExecuteQueryRetry(); - WriteObject(safeDomain); - } - else - { - WriteWarning($"Unable to add Domain Name as there is an existing domain name with the same name. Will be skipped."); - } - } - } -} diff --git a/src/Commands/Site/SetSite.cs b/src/Commands/Site/SetSite.cs index eaa4d0dba..7d6ebf4c7 100644 --- a/src/Commands/Site/SetSite.cs +++ b/src/Commands/Site/SetSite.cs @@ -144,12 +144,30 @@ protected override void ExecuteCmdlet() if (ParameterSpecified(nameof(ScriptSafeDomainName)) && !string.IsNullOrEmpty(ScriptSafeDomainName)) { - ScriptSafeDomainEntityData scriptSafeDomainEntity = new ScriptSafeDomainEntityData + ScriptSafeDomain safeDomain = null; + try { - DomainName = ScriptSafeDomainName - }; - site.CustomScriptSafeDomains.Create(scriptSafeDomainEntity); - context.ExecuteQueryRetry(); + safeDomain = ClientContext.Site.CustomScriptSafeDomains.GetByDomainName(ScriptSafeDomainName); + ClientContext.Load(safeDomain); + ClientContext.ExecuteQueryRetry(); + } + catch { } + if (safeDomain.ServerObjectIsNull == null) + { + ScriptSafeDomainEntityData scriptSafeDomainEntity = new ScriptSafeDomainEntityData + { + DomainName = ScriptSafeDomainName + }; + + safeDomain = context.Site.CustomScriptSafeDomains.Create(scriptSafeDomainEntity); + context.Load(safeDomain); + context.ExecuteQueryRetry(); + WriteObject(safeDomain); + } + else + { + WriteWarning($"Unable to add Domain Name as there is an existing domain name with the same name. Will be skipped."); + } } if (ParameterSpecified(nameof(LogoFilePath))) From e5977227c5dced3d7db255a5cdac280c838edd5f Mon Sep 17 00:00:00 2001 From: reshmee011 Date: Tue, 1 Aug 2023 01:08:45 +0100 Subject: [PATCH 3/4] Changes to update and retrieve property SiteOwnerManageLegacyServicePrincipalEnabled --- src/Commands/Admin/SetTenant.cs | 8 ++++++++ src/Commands/Model/SPOTenant.cs | 14 +++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Commands/Admin/SetTenant.cs b/src/Commands/Admin/SetTenant.cs index 0244b934f..05747bf93 100644 --- a/src/Commands/Admin/SetTenant.cs +++ b/src/Commands/Admin/SetTenant.cs @@ -380,6 +380,8 @@ public class SetTenant : PnPAdminCmdlet [Parameter(Mandatory = false)] public MediaTranscriptionAutomaticFeaturesPolicyType? MediaTranscriptionAutomaticFeatures { get; set; } + [Parameter(Mandatory = false)] + public bool? SiteOwnerManageLegacyServicePrincipalEnabled { get; set; } protected override void ExecuteCmdlet() { AdminContext.Load(Tenant); @@ -1266,6 +1268,12 @@ protected override void ExecuteCmdlet() modified = true; } + if (SiteOwnerManageLegacyServicePrincipalEnabled.HasValue) + { + Tenant.SiteOwnerManageLegacyServicePrincipalEnabled = SiteOwnerManageLegacyServicePrincipalEnabled.Value; + modified = true; + } + if (BlockDownloadFileTypePolicy.HasValue) { if (!BlockDownloadFileTypePolicy.Value) diff --git a/src/Commands/Model/SPOTenant.cs b/src/Commands/Model/SPOTenant.cs index e95ab2cb4..7b0b7bb1b 100644 --- a/src/Commands/Model/SPOTenant.cs +++ b/src/Commands/Model/SPOTenant.cs @@ -42,6 +42,7 @@ public SPOTenant(Tenant tenant, ClientContext clientContext) this.displayNamesOfFileViewersInSpo = tenant.DisplayNamesOfFileViewersInSpo; this.isLoopEnabled = tenant.IsLoopEnabled; this.enableAzureADB2BIntegration = tenant.EnableAzureADB2BIntegration; + this.siteOwnerManageLegacyServicePrincipalEnabled = tenant.SiteOwnerManageLegacyServicePrincipalEnabled; try { @@ -461,7 +462,15 @@ public SPOTenant(Tenant tenant, ClientContext clientContext) } catch { - } + } + + try + { + this.siteOwnerManageLegacyServicePrincipalEnabled = tenant.SiteOwnerManageLegacyServicePrincipalEnabled; + } + catch + { + } } public bool HideDefaultThemes => hideDefaultThemes; @@ -630,6 +639,7 @@ public SPOTenant(Tenant tenant, ClientContext clientContext) public int? MajorVersionLimit => majorVersionLimit; public bool? EnableAutoExpirationVersionTrim => enableAutoExpirationVersionTrim; public bool? EnableAzureADB2BIntegration => enableAzureADB2BIntegration; + public bool? SiteOwnerManageLegacyServicePrincipalEnabled => siteOwnerManageLegacyServicePrincipalEnabled; private bool hideDefaultThemes; @@ -808,5 +818,7 @@ public SPOTenant(Tenant tenant, ClientContext clientContext) private bool? enableAutoExpirationVersionTrim; private bool? enableAzureADB2BIntegration; + + private bool? siteOwnerManageLegacyServicePrincipalEnabled; } } From e46e9f21ecccfb94e4818853a9f60787a1f47092 Mon Sep 17 00:00:00 2001 From: reshmee011 Date: Tue, 1 Aug 2023 01:15:30 +0100 Subject: [PATCH 4/4] Update md related to SiteOwnerManageLegacyServicePrincipalEnabled --- documentation/Set-PnPTenant.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/documentation/Set-PnPTenant.md b/documentation/Set-PnPTenant.md index 73d5af6a6..ed7328998 100644 --- a/documentation/Set-PnPTenant.md +++ b/documentation/Set-PnPTenant.md @@ -127,6 +127,7 @@ Set-PnPTenant [-SpecialCharactersStateInFileFolderNames [-StopNew2013Workflows ] [-MediaTranscription ] [-MediaTranscriptionAutomaticFeatures ] + [-SiteOwnerManageLegacyServicePrincipalEnabled ] [-Force] [-Connection ] ``` @@ -2151,6 +2152,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -SiteOwnerManageLegacyServicePrincipalEnabled + +This parameter allows site owners to create or update the service principal. + +```yaml +Type: Boolean +Parameter Sets: (All) + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Force If provided, no confirmation will be requested and the action will be performed