Blocking external iframe embedding via powershell

Spencer Cooper 201 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

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,556 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,353 questions
0 comments No comments
{count} votes

Accepted answer
  1. Spencer Cooper 201 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

1 additional answer

Sort by: Most helpful
  1. Rich Matheisen 44,621 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.