Skip to content

Commit 91b1c84

Browse files
cmdlet to add ScriptSafeDomain (#3073)
* New cmdlet to add script safe domain * Merge ScriptSafeDomain into SetSite --------- Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com>
1 parent b2fcc6a commit 91b1c84

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/Commands/Site/SetSite.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,30 @@ protected override void ExecuteCmdlet()
153153

154154
if (ParameterSpecified(nameof(ScriptSafeDomainName)) && !string.IsNullOrEmpty(ScriptSafeDomainName))
155155
{
156-
ScriptSafeDomainEntityData scriptSafeDomainEntity = new ScriptSafeDomainEntityData
156+
ScriptSafeDomain safeDomain = null;
157+
try
157158
{
158-
DomainName = ScriptSafeDomainName
159-
};
160-
site.CustomScriptSafeDomains.Create(scriptSafeDomainEntity);
161-
context.ExecuteQueryRetry();
159+
safeDomain = ClientContext.Site.CustomScriptSafeDomains.GetByDomainName(ScriptSafeDomainName);
160+
ClientContext.Load(safeDomain);
161+
ClientContext.ExecuteQueryRetry();
162+
}
163+
catch { }
164+
if (safeDomain.ServerObjectIsNull == null)
165+
{
166+
ScriptSafeDomainEntityData scriptSafeDomainEntity = new ScriptSafeDomainEntityData
167+
{
168+
DomainName = ScriptSafeDomainName
169+
};
170+
171+
safeDomain = context.Site.CustomScriptSafeDomains.Create(scriptSafeDomainEntity);
172+
context.Load(safeDomain);
173+
context.ExecuteQueryRetry();
174+
WriteObject(safeDomain);
175+
}
176+
else
177+
{
178+
WriteWarning($"Unable to add Domain Name as there is an existing domain name with the same name. Will be skipped.");
179+
}
162180
}
163181

164182
if (ParameterSpecified(nameof(LogoFilePath)))

0 commit comments

Comments
 (0)