question

RowdeyCooper-5247 avatar image
0 Votes"
RowdeyCooper-5247 asked RowdeyCooper-5247 answered

How to remove domains within HTML Field Security settings via powershell

As the title states, I am working on a script and need to have the ability to remove links from the allowed domains section of HTML Field Security of Sharepoint Online.....

as an example the below code successfully adds links.

Set Variables

$SiteURL = "https://crescentintranet.sharepoint.com/sites/marketing"


Connect to PnP Online

Connect-PnPOnline -Url $SiteURL -UseWebLogin


Get the Site

$Site = Get-PnPSite -Includes CustomScriptSafeDomains


Add domain

$Domain = [Microsoft.SharePoint.Client.ScriptSafeDomainEntityData]::new()
$Domain.DomainName = "products.crescent.com"
$Site.CustomScriptSafeDomains.Create($Domain)
Invoke-PnPQuery

office-sharepoint-onlinewindows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RowdeyCooper-5247 avatar image
1 Vote"
RowdeyCooper-5247 answered

Solved this with the following code

$removed= $Site.CustomScriptSafeDomains.GetByDomainName("test.com")
$removed.deleteobject()

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ElsieLu-MSFT avatar image
0 Votes"
ElsieLu-MSFT answered RowdeyCooper-5247 commented

Hi @RowdeyCooper-5247 ,

You could try to remove links manully:

134994-72.png


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


72.png (96.8 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Unfortunately,
It has to be done via powershell only no gui.

0 Votes 0 ·
LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered RichMatheisen-8856 commented

Hello RowdeyCooper,

Your code seems completely fine to me.

But before code execution Add Trusted Domain To HTML Field security List using the below step.

Online Site Collection >> Site Settings >> Select "HTML Field Security" from Site Collection Administration.

Choose Allow Contributors to insert iframe" Option

Add your preference and Click Ok.

and consider Switching On the Custom Script before the process.



Hope this answers all your queries, if not please do repost back.
If an Answer is helpful, please click "Accept Answer" and upvote it : )

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

While I appreciate the feedback, I was asking how to remove the links the addition part is working just fine.

0 Votes 0 ·

You may have to examine the contents of that property, which I believe is a collection, to remove the domain from the collection and then set the modified property and rewrite the site object.

The only thing I found was a Microsoft UserVoice request made a year (or two) ago to add the ability to "modify" the site property using a cmdlet. I didn't check to see if there were any answers to the request though. It might something for you to follow up on.

0 Votes 0 ·