Skip to content

Instantly share code, notes, and snippets.

@KanwarSingh
Created April 3, 2019 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KanwarSingh/d6db7afd7f7e3798584e2d139752157b to your computer and use it in GitHub Desktop.
Save KanwarSingh/d6db7afd7f7e3798584e2d139752157b to your computer and use it in GitHub Desktop.
Enable External Domain in SPO
Tenant tenant = new Tenant(_context);
SPOSitePropertiesEnumerable prop = null;
prop = tenant.GetSiteProperties(0, true);
_context.Load(prop);
_context.ExecuteQuery();
foreach (SiteProperties sp in prop)
{
try
{
var site_cxt = new ClientContext(sp.Url);
site_cxt.Credentials = sp.Context.Credentials;
var web = site_cxt.Web;
var site = site_cxt.Site;
site_cxt.Load(web, w => w.SiteUsers);
site_cxt.Load(site);
site_cxt.ExecuteQuery();
ScriptSafeDomainEntityData ssded = new ScriptSafeDomainEntityData();
ssded.DomainName = ("http://External-Domain-to-be-added-to-spo");
site.CustomScriptSafeDomains.Create(ssded);
site_cxt.ExecuteQueryRetry();
Console.WriteLine(" **** External-Domain added to the site **** " + " : " + sp.Url + "");
strbldr.AppendLine(" **** External-Domain added to the site **** " + " : " + sp.Url + "");
}
catch (Exception ex)
{
Console.WriteLine("---- Exception --- * *" + sp.Url + " - " + ex.Message);
strbldr.AppendLine(" ---- Exception --- * *" + sp.Url + " - " + ex.Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment