Blocking external iframe embedding via powershell

Rowdey Cooper 201 Reputation points


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

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
7,122 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.
4,901 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rowdey Cooper 201 Reputation points

    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 39,266 Reputation points

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