Exemple #1
0
        protected override void ExecuteCmdlet()
        {
            var url       = SelectedWeb.EnsureProperty(w => w.Url);
            var tenantUrl = UrlUtilities.GetTenantAdministrationUrl(ClientContext.Url);

            using (var tenantContext = ClientContext.Clone(tenantUrl))
            {
                var webUrl = url;
                if (!string.IsNullOrEmpty(WebUrl))
                {
                    try
                    {
                        var uri = new System.Uri(WebUrl);
                        webUrl = WebUrl;
                    }
                    catch
                    {
                        ThrowTerminatingError(new ErrorRecord(new System.Exception("Invalid URL"), "INVALIDURL", ErrorCategory.InvalidArgument, WebUrl));
                    }
                }
                try
                {
                    var designTask = Tenant.AddSiteDesignTask(tenantContext, webUrl, SiteDesignId.Id);
                    tenantContext.Load(designTask);
                    tenantContext.ExecuteQueryRetry();
                    WriteObject(designTask);
                }
                catch (System.Net.WebException ex)
                {
                    if (ex.Status == System.Net.WebExceptionStatus.ProtocolError)
                    {
                        var webResponse = ex.Response as System.Net.HttpWebResponse;
                        if (null != webResponse &&
                            webResponse.StatusCode == System.Net.HttpStatusCode.Forbidden)
                        {
                            WriteObject("The server threw an exception (see below). It seems you may not have access to the server or you are executing this script outside of the tenant admin URL eg. yourtenant-admin.sharepoint.com. Please connect to the tenant admin URL first and try again.");
                        }
                    }
                    WriteObject(ex);
                }
            }
        }
        protected override void ExecuteCmdlet()
        {
            var url       = SelectedWeb.EnsureProperty(w => w.Url);
            var tenantUrl = UrlUtilities.GetTenantAdministrationUrl(ClientContext.Url);

            using (var tenantContext = ClientContext.Clone(tenantUrl))
            {
                var webUrl = url;
                if (!string.IsNullOrEmpty(WebUrl))
                {
                    try
                    {
                        var uri = new System.Uri(WebUrl);
                        webUrl = WebUrl;
                    }
                    catch
                    {
                        ThrowTerminatingError(new ErrorRecord(new System.Exception("Invalid URL"), "INVALIDURL", ErrorCategory.InvalidArgument, WebUrl));
                    }
                }
                Tenant.AddSiteDesignTask(tenantContext, webUrl, SiteDesignId.Id);
            }
        }