Blocking external iframe embedding via powershell

Spencer Cooper 11 Reputation points
2021-09-21T17:50:49.753+00:00

Hello,

I am trying to write a script that automatically changes the html field security settings to block external iframe embedding.

I've googled some guides and tried the attached code. But as you can see it keeps erroring out. Any ideas on how to fix it?134199-134040-error.jpg

Microsoft 365 and Office SharePoint For business Windows
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Spencer Cooper 11 Reputation points
    2021-09-22T07:16:05.733+00:00

    For anyone else who has this problem I figured out the solution was due to different .dll's used for sharepoint vs sharepoint online.

    Working code for sharepoint online is:

    $SiteURL = "Your URL Here"
    Connect-PnPOnline -Url $SiteURL -UseWebLogin
    $Site = Get-PnPSite -Includes CustomScriptSafeDomains

    This allows for any domain

    $site.AllowExternalEmbeddingWrapper = [Microsoft.SharePoint.Client.ScriptSafeExternalEmbedding]::AllowedDomains;

    This blocks any domain

    $site.AllowExternalEmbeddingWrapper = [Microsoft.SharePoint.Client.ScriptSafeExternalEmbedding]::None;

    1 person found this answer helpful.
    0 comments No comments

  2. Rich Matheisen 47,901 Reputation points
    2021-09-21T18:25:06.13+00:00

    I don't have SharePoint, but it looks like you need to use the Add-Type cmdlet to load the Microsoft.Sharepoint assembly.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.