Register a Script Safe Domain for your SharePoint 2013 Site Collection using PowerShell

​Every now and then, I go mess around in the SharePoint object model using PowerShell to see if there are any hidden gems that could be of interest. Today, I’ve discovered a per-site collection setting called ScriptSafeDomains that contains a list of all domains from which SharePoint will allow loading scripts from. In order for you to get a list of those, you can execute the following line of PowerShell:

Get-SPSite http://<your site url> | Select ScriptSafeDomains


We can see from the figure above that default domains include,,, etc. It seems as if this property would be some kind of a Cross-Origin Resource Sharing (CORS) white list. To test my theory, I tried the following scenario where I tried to embed a video from Using the Embed code function from the SharePoint insert ribbon, I added the following iFrame tag to my site:


We can see from the figure above that SharePoint adds the mention This HTML will be inserted in a web part, and the resulting webpart doesn’t properly allow us to play the video very well. What we need to do here is to add  to our list of SafeScriptDomains. In order to do this, we can execute the following lines of PowerShell:

$site = Get-SPSite http://<your site url>


Then if you refresh the page and try to add the embeded code again, you should be able to do it just like you would be embedding a YouTube video. The notification that it will be inserted through a web part should now be gone!


Leave a Reply

Your email address will not be published. Required fields are marked *