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);
                }
            }
        }
Exemple #2
0
        protected override void ExecuteCmdlet()
        {
            var serverRelativeWebUrl = SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl);

            if (!ServerRelativePageUrl.ToLowerInvariant().StartsWith(serverRelativeWebUrl.ToLowerInvariant()))
            {
                ServerRelativePageUrl = UrlUtility.Combine(serverRelativeWebUrl, ServerRelativePageUrl);
            }


            WebPartEntity wp = null;

            switch (ParameterSetName)
            {
            case "FILE":
                if (!System.IO.Path.IsPathRooted(Path))
                {
                    Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path);
                }
                if (File.Exists(Path))
                {
                    var fileStream    = new StreamReader(Path);
                    var webPartString = fileStream.ReadToEnd();
                    fileStream.Close();

                    wp = new WebPartEntity {
                        WebPartXml = webPartString
                    };
                }
                break;

            case "XML":
                wp = new WebPartEntity {
                    WebPartXml = Xml
                };
                break;
            }
            if (wp != null)
            {
                SelectedWeb.AddWebPartToWikiPage(ServerRelativePageUrl, wp, Row, Column, AddSpace);
            }
        }
 protected override void ExecuteCmdlet()
 {
     if (!ParameterSpecified(nameof(AllAvailable)) && !ParameterSpecified(nameof(Name)))
     {
         // Return the current applied site policy
         WriteObject(this.SelectedWeb.GetAppliedSitePolicy());
     }
     else
     {
         if (ParameterSpecified(nameof(AllAvailable)))
         {
             WriteObject(SelectedWeb.GetSitePolicies(), true);
             return;
         }
         if (ParameterSpecified(nameof(Name)))
         {
             WriteObject(SelectedWeb.GetSitePolicyByName(Name));
         }
     }
 }
        protected override void ExecuteCmdlet()
        {
            if (ParameterSetName == ParameterSet_SITE)
            {
                var webUrl = SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl);
                ServerRelativeUrl = UrlUtility.Combine(webUrl, SiteRelativeUrl);
            }

            var file = SelectedWeb.GetFileByServerRelativeUrl(ServerRelativeUrl);

            ClientContext.Load(file, f => f.Name);
            ClientContext.ExecuteQueryRetry();

            if (Force || ShouldContinue(string.Format(Resources.MoveFile0To1, ServerRelativeUrl, TargetUrl), Resources.Confirm))
            {
                file.MoveTo(TargetUrl, OverwriteIfAlreadyExists ? MoveOperations.Overwrite : MoveOperations.None);

                ClientContext.ExecuteQueryRetry();
            }
        }
Exemple #5
0
 protected override void ExecuteCmdlet()
 {
     if (Identity != null)
     {
         var instance = Identity.GetAppInstance(SelectedWeb);
         WriteObject(instance);
     }
     else
     {
         var instances = SelectedWeb.GetAppInstances();
         if (instances.Count > 1)
         {
             WriteObject(instances, true);
         }
         else if (instances.Count == 1)
         {
             WriteObject(instances[0]);
         }
     }
 }
Exemple #6
0
        protected override void ExecuteCmdlet()
        {
            SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl);

            Folder sourceFolder = SelectedWeb.GetFolderByServerRelativeUrl(UrlUtility.Combine(SelectedWeb.ServerRelativeUrl, Folder));

            ClientContext.Load(sourceFolder, f => f.Name, f => f.ServerRelativeUrl);
            ClientContext.ExecuteQueryRetry();

            var targetPath = string.Concat(TargetFolder, "/", sourceFolder.Name);

            sourceFolder.MoveTo(targetPath);
            ClientContext.ExecuteQueryRetry();

            var folder = SelectedWeb.GetFolderByServerRelativeUrl(targetPath);

            ClientContext.Load(folder, f => f.Name, f => f.ItemCount, f => f.TimeLastModified, f => f.ListItemAllFields);
            ClientContext.ExecuteQueryRetry();
            WriteObject(folder);
        }
Exemple #7
0
        protected override void ExecuteCmdlet()
        {
            if (ParameterSetName == "SITE")
            {
                var webUrl = SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl);
                ServerRelativeUrl = UrlUtility.Combine(webUrl, SiteRelativeUrl);
            }

            var file = SelectedWeb.GetFileByServerRelativeUrl(ServerRelativeUrl);

            ClientContext.Load(file, f => f.Name);
            ClientContext.ExecuteQueryRetry();

            if (Force || ShouldContinue(string.Format(Resources.Delete0, file.Name), Resources.Confirm))
            {
                file.DeleteObject();

                ClientContext.ExecuteQueryRetry();
            }
        }
Exemple #8
0
 protected override void ExecuteCmdlet()
 {
     if (!MyInvocation.BoundParameters.ContainsKey("AllAvailable") && !MyInvocation.BoundParameters.ContainsKey("Name"))
     {
         // Return the current applied site policy
         WriteObject(this.SelectedWeb.GetAppliedSitePolicy());
     }
     else
     {
         if (MyInvocation.BoundParameters.ContainsKey("AllAvailable"))
         {
             WriteObject(SelectedWeb.GetSitePolicies(), true);
             return;
         }
         if (MyInvocation.BoundParameters.ContainsKey("Name"))
         {
             WriteObject(SelectedWeb.GetSitePolicyByName(Name));
         }
     }
 }
        protected override void ExecuteCmdlet()
        {
            if (ParameterSetName == "SITE")
            {
                var webUrl = SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl);
                ServerRelativeUrl = UrlUtility.Combine(webUrl, SiteRelativeUrl);
            }
            var file = SelectedWeb.GetFileByServerRelativePath(ResourcePath.FromDecodedUrl(ServerRelativeUrl));

            ClientContext.Load(file, f => f.Name, f => f.ServerRelativePath);
            ClientContext.ExecuteQueryRetry();

            if (Force || ShouldContinue(string.Format(Resources.RenameFile0To1, file.Name, TargetFileName), Resources.Confirm))
            {
                var targetPath = string.Concat(file.ServerRelativePath.DecodedUrl.Remove(file.ServerRelativePath.DecodedUrl.Length - file.Name.Length), TargetFileName);
                file.MoveToUsingPath(ResourcePath.FromDecodedUrl(targetPath), OverwriteIfAlreadyExists ? MoveOperations.Overwrite : MoveOperations.None);

                ClientContext.ExecuteQueryRetry();
            }
        }
        protected override void ExecuteCmdlet()
        {
            List <UserCustomAction> actions = new List <UserCustomAction>();

            if (Scope == CustomActionScope.All || Scope == CustomActionScope.Web)
            {
                actions.AddRange(SelectedWeb.GetCustomActions(RetrievalExpressions));
            }
            if (Scope == CustomActionScope.All || Scope == CustomActionScope.Site)
            {
                actions.AddRange(ClientContext.Site.GetCustomActions(RetrievalExpressions));
            }

            if (Identity != null)
            {
                var foundAction = actions.FirstOrDefault(x => x.Id == Identity.Id && x.Location == "ClientSideExtension.ApplicationCustomizer");
                if (foundAction != null || !ThrowExceptionIfCustomActionNotFound)
                {
                    WriteObject(foundAction, true);
                }
                else
                {
                    throw new PSArgumentException($"No SharePoint Framework client side extension application customizer found with the Identity '{Identity.Id}' within the scope '{Scope}'", "Identity");
                }
            }
            else
            {
                switch (ParameterSetName)
                {
                case ParameterSet_CLIENTSIDECOMPONENTID:
                    actions = actions.Where(x => x.Location == "ClientSideExtension.ApplicationCustomizer" & x.ClientSideComponentId == ClientSideComponentId.Id).ToList();
                    break;

                case ParameterSet_CUSTOMACTIONID:
                    actions = actions.Where(x => x.Location == "ClientSideExtension.ApplicationCustomizer").ToList();
                    break;
                }

                WriteObject(actions, true);
            }
        }
        protected override void ExecuteCmdlet()
        {
            if (List != null)
            {
                var list = List.GetList(SelectedWeb);

                if (string.IsNullOrEmpty(Name))
                {
                    var servicesManager     = new WorkflowServicesManager(ClientContext, SelectedWeb);
                    var subscriptionService = servicesManager.GetWorkflowSubscriptionService();
                    var subscriptions       = subscriptionService.EnumerateSubscriptionsByList(list.Id);

                    ClientContext.Load(subscriptions);

                    ClientContext.ExecuteQueryRetry();
                    WriteObject(subscriptions, true);
                }
                else
                {
                    WriteObject(list.GetWorkflowSubscription(Name));
                }
            }
            else
            {
                if (string.IsNullOrEmpty(Name))
                {
                    var servicesManager     = new WorkflowServicesManager(ClientContext, SelectedWeb);
                    var subscriptionService = servicesManager.GetWorkflowSubscriptionService();
                    var subscriptions       = subscriptionService.EnumerateSubscriptions();

                    ClientContext.Load(subscriptions);

                    ClientContext.ExecuteQueryRetry();
                    WriteObject(subscriptions, true);
                }
                else
                {
                    WriteObject(SelectedWeb.GetWorkflowSubscription(Name));
                }
            }
        }
Exemple #12
0
        protected override void ExecuteCmdlet()
        {
            var properties = SelectedWeb.GetWebPartProperties(Identity.Id, PageUrl);
            var values     = properties.FieldValues.Select(x => new PropertyBagValue()
            {
                Key = x.Key, Value = x.Value
            });

            if (!string.IsNullOrEmpty(Key))
            {
                var value = values.FirstOrDefault(v => v.Key == Key);
                if (value != null)
                {
                    WriteObject(value.Value);
                }
            }
            else
            {
                WriteObject(values, true);
            }
        }
Exemple #13
0
 protected override void ExecuteCmdlet()
 {
     try
     {
         Group group = SelectedWeb.SiteGroups.GetByName(GroupName);
         User  user  = SelectedWeb.SiteUsers.GetByEmail(LoginName);
         ClientContext.Load(user);
         ClientContext.Load(group);
         ClientContext.ExecuteQueryRetry();
         SelectedWeb.RemoveUserFromGroup(group, user);
     }
     catch
     {
         Group group = SelectedWeb.SiteGroups.GetByName(GroupName);
         User  user  = SelectedWeb.SiteUsers.GetByLoginName(LoginName);
         ClientContext.Load(user);
         ClientContext.Load(group);
         ClientContext.ExecuteQueryRetry();
         SelectedWeb.RemoveUserFromGroup(group, user);
     }
 }
        protected override void ExecuteCmdlet()
        {
#if !SP2013
            DefaultRetrievalExpressions = new Expression <Func <Folder, object> >[] { f => f.ServerRelativeUrl, f => f.Name, f => f.TimeLastModified, f => f.ItemCount };
#else
            DefaultRetrievalExpressions = new Expression <Func <Folder, object> >[] { f => f.ServerRelativeUrl, f => f.Name, f => f.ItemCount };
#endif
            var webServerRelativeUrl = SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl);
            if (!Url.StartsWith(webServerRelativeUrl, StringComparison.OrdinalIgnoreCase))
            {
                Url = UrlUtility.Combine(webServerRelativeUrl, Url);
            }
#if ONPREMISES
            var folder = SelectedWeb.GetFolderByServerRelativeUrl(Url);
#else
            var folder = SelectedWeb.GetFolderByServerRelativePath(ResourcePath.FromDecodedUrl(Url));
#endif
            folder.EnsureProperties(RetrievalExpressions);

            WriteObject(folder);
        }
Exemple #15
0
        protected override void ExecuteCmdlet()
        {
            var list = SelectedWeb.GetList(Identity);

            if (list != null)
            {
                if (BreakRoleInheritance)
                {
                    list.BreakRoleInheritance(CopyRoleAssignments, ClearSubscopes);
                    list.Update();
                    ClientContext.ExecuteQueryRetry();
                }

                if (!string.IsNullOrEmpty(Title))
                {
                    list.Title = Title;
                    list.Update();
                    ClientContext.ExecuteQueryRetry();
                }
            }
        }
        protected override void ExecuteCmdlet()
        {
            if (ParameterSetName == "SPECIFIC")
            {
                if (PageLayouts.Length < 1)
                {
                    throw new ArgumentException("You must provide at least 1 page layout.");
                }

                var rootWeb = ClientContext.Site.RootWeb;
                SelectedWeb.SetAvailablePageLayouts(rootWeb, PageLayouts);
            }
            else if (ParameterSetName == "INHERIT")
            {
                SelectedWeb.SetSiteToInheritPageLayouts();
            }
            else
            {
                SelectedWeb.AllowAllPageLayouts();
            }
        }
Exemple #17
0
 protected override void ExecuteCmdlet()
 {
     if (!string.IsNullOrEmpty(Key))
     {
         WriteObject(SelectedWeb.GetPropertyBagValueString(Key, string.Empty));
     }
     else
     {
         if (SelectedWeb.IsPropertyAvailable("AllProperties"))
         {
             WriteObject(SelectedWeb.AllProperties.FieldValues);
         }
         else
         {
             var values = SelectedWeb.AllProperties;
             ClientContext.Load(values);
             ClientContext.ExecuteQueryRetry();
             WriteObject(values.FieldValues);
         }
     }
 }
Exemple #18
0
        protected override void ExecuteCmdlet()
        {
            if (ParameterSetName == "Web")
            {
                if (!Indexed)
                {
                    // If it is already an indexed property we still have to add it back to the indexed properties
                    Indexed = !string.IsNullOrEmpty(SelectedWeb.GetIndexedPropertyBagKeys().FirstOrDefault(k => k == Key));
                }

                SelectedWeb.SetPropertyBagValue(Key, Value);
                if (Indexed)
                {
                    SelectedWeb.AddIndexedPropertyBagKey(Key);
                }
                else
                {
                    SelectedWeb.RemoveIndexedPropertyBagKey(Key);
                }
            }
            else
            {
                if (!SelectedWeb.IsPropertyAvailable("ServerRelativeUrl"))
                {
                    ClientContext.Load(SelectedWeb, w => w.ServerRelativeUrl);
                    ClientContext.ExecuteQueryRetry();
                }

                var folderUrl = UrlUtility.Combine(SelectedWeb.ServerRelativeUrl, Folder);
                var folder    = SelectedWeb.GetFolderByServerRelativeUrl(folderUrl);
                if (!folder.IsPropertyAvailable("Properties"))
                {
                    ClientContext.Load(folder.Properties);
                    ClientContext.ExecuteQueryRetry();
                }
                folder.Properties[Key] = Value;
                folder.Update();
                ClientContext.ExecuteQueryRetry();
            }
        }
Exemple #19
0
        protected override void ExecuteCmdlet()
        {
            WorkflowServicesManager workflowServicesManager = new WorkflowServicesManager(ClientContext, SelectedWeb);
            InteropService          interopService          = workflowServicesManager.GetWorkflowInteropService();
            WorkflowInstanceService instanceService         = workflowServicesManager.GetWorkflowInstanceService();

            if (Identity.Instance != null)
            {
                WriteVerbose("Instance object set");
                WriteVerbose("Cancelling workflow with ID: " + Identity.Instance.Id);
                if (Force)
                {
                    instanceService.TerminateWorkflow(Identity.Instance);
                }
                else
                {
                    Identity.Instance.CancelWorkFlow();
                }
                ClientContext.ExecuteQuery();
            }
            else if (Identity.Id != Guid.Empty)
            {
                WriteVerbose("Instance object not set. Looking up site workflows by GUID: " + Identity.Id);
                var allinstances = SelectedWeb.GetWorkflowInstances();
                foreach (var instance in allinstances.Where(instance => instance.Id == Identity.Id))
                {
                    WriteVerbose("Cancelling workflow with ID: " + Identity.Instance.Id);
                    if (Force)
                    {
                        instanceService.TerminateWorkflow(instance);
                    }
                    else
                    {
                        instance.CancelWorkFlow();
                    }
                    ClientContext.ExecuteQuery();
                    break;
                }
            }
        }
Exemple #20
0
        protected override void ExecuteCmdlet()
        {
            SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl);

            Folder folder = SelectedWeb.GetFolderByServerRelativeUrl(UrlUtility.Combine(SelectedWeb.ServerRelativeUrl, Folder, Name));

            folder.EnsureProperty(f => f.Name);

            if (Force || ShouldContinue(string.Format(Resources.Delete0, folder.Name), Resources.Confirm))
            {
                if (Recycle)
                {
                    folder.Recycle();
                }
                else
                {
                    folder.DeleteObject();
                }

                ClientContext.ExecuteQueryRetry();
            }
        }
        protected override void ExecuteCmdlet()
        {
            if (SelectedWeb.IsNoScriptSite())
            {
                ThrowTerminatingError(new ErrorRecord(new Exception("Site has NoScript enabled, and setting property bag values is not supported"), "NoScriptEnabled", ErrorCategory.InvalidOperation, this));
                return;
            }
            if (!MyInvocation.BoundParameters.ContainsKey("Folder"))
            {
                if (!Indexed)
                {
                    // If it is already an indexed property we still have to add it back to the indexed properties
                    Indexed = !string.IsNullOrEmpty(SelectedWeb.GetIndexedPropertyBagKeys().FirstOrDefault(k => k == Key));
                }

                SelectedWeb.SetPropertyBagValue(Key, Value);
                if (Indexed)
                {
                    SelectedWeb.AddIndexedPropertyBagKey(Key);
                }
                else
                {
                    SelectedWeb.RemoveIndexedPropertyBagKey(Key);
                }
            }
            else
            {
                SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl);

                var folderUrl = UrlUtility.Combine(SelectedWeb.ServerRelativeUrl, Folder);
                var folder    = SelectedWeb.GetFolderByServerRelativeUrl(folderUrl);

                folder.EnsureProperty(f => f.Properties);

                folder.Properties[Key] = Value;
                folder.Update();
                ClientContext.ExecuteQueryRetry();
            }
        }
Exemple #22
0
        protected override void ExecuteCmdlet()
        {
            if (string.IsNullOrEmpty(Path))
            {
                Path = SessionState.Path.CurrentFileSystemLocation.Path;
            }

            if (ParameterSetName == "SITE")
            {
                var webUrl = SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl);
                ServerRelativeUrl = UrlUtility.Combine(webUrl, SiteRelativeUrl);
            }

            if (MyInvocation.BoundParameters.ContainsKey("AsString"))
            {
                WriteObject(SelectedWeb.GetFileAsString(ServerRelativeUrl));
            }
            else
            {
                SelectedWeb.SaveFileToLocal(ServerRelativeUrl, Path, Filename);
            }
        }
Exemple #23
0
        protected override void ExecuteCmdlet()
        {
            if (string.IsNullOrEmpty(Folder))
            {
                if (SelectedWeb.PropertyBagContainsKey(Key))
                {
                    if (Force || ShouldContinue(string.Format(Properties.Resources.Delete0, Key), Properties.Resources.Confirm))
                    {
                        SelectedWeb.RemovePropertyBagValue(Key);
                    }
                }
            }
            else
            {
                if (!SelectedWeb.IsPropertyAvailable("ServerRelativeUrl"))
                {
                    ClientContext.Load(SelectedWeb, w => w.ServerRelativeUrl);
                    ClientContext.ExecuteQueryRetry();
                }

                var folderUrl = UrlUtility.Combine(SelectedWeb.ServerRelativeUrl, Folder);
                var folder    = SelectedWeb.GetFolderByServerRelativeUrl(folderUrl);
                if (!folder.IsPropertyAvailable("Properties"))
                {
                    ClientContext.Load(folder.Properties);
                    ClientContext.ExecuteQueryRetry();
                }
                if (folder.Properties.FieldValues.ContainsKey(Key))
                {
                    if (Force || ShouldContinue(string.Format(Properties.Resources.Delete0, Key), Properties.Resources.Confirm))
                    {
                        folder.Properties[Key] = null;
                        folder.Properties.FieldValues.Remove(Key);
                        folder.Update();
                        ClientContext.ExecuteQueryRetry();
                    }
                }
            }
        }
Exemple #24
0
 protected override void ExecuteCmdlet()
 {
     if (SelectedWeb.PropertyBagContainsKey("_PnP_ProvisioningTemplateComposedLookInfo") && !DetectCurrentComposedLook)
     {
         try
         {
             WriteWarning("The information presented here is based upon the fact that the theme has been set using either the PnP Provisioning Engine or using the Set-PnPTheme cmdlet. This information is retrieved from a propertybag value and may differ from the actual site.");
             var composedLook = JsonSerializer.Deserialize <ComposedLook>(SelectedWeb.GetPropertyBagValueString("_PnP_ProvisioningTemplateComposedLookInfo", ""));
             WriteObject(composedLook);
         }
         catch
         {
             var themeEntity = SelectedWeb.GetCurrentComposedLook();
             WriteObject(themeEntity);
         }
     }
     else
     {
         var themeEntity = SelectedWeb.GetCurrentComposedLook();
         WriteObject(themeEntity);
     }
 }
Exemple #25
0
 protected override void ExecuteCmdlet()
 {
     if (Identity != null)
     {
         var instance = SelectedWeb.GetAppInstanceById(Identity.Id);
         ClientContext.Load(instance);
         ClientContext.ExecuteQueryRetry();
         WriteObject(instance);
     }
     else
     {
         var instances = SelectedWeb.GetAppInstances();
         if (instances.Count > 1)
         {
             WriteObject(instances, true);
         }
         else if (instances.Count == 1)
         {
             WriteObject(instances[0]);
         }
     }
 }
        protected override void ExecuteCmdlet()
        {
            SelectedWeb.EnsureProperty(w => w.HasUniqueRoleAssignments);

            // Can only set the Request Access Emails if the web has unique permissions
            if (SelectedWeb.HasUniqueRoleAssignments)
            {
                if (Emails != null && Emails.Length > 0 && !Disabled)
                {
                    if (Emails.Length > 1)
                    {
                        // Only one e-mail address can be configured to receive the access requests
                        throw new ArgumentException(Resources.SetRequestAccessEmailsOnlyOneAddressAllowed, nameof(Emails));
                    }
                    else
                    {
                        // Configure the one e-mail address to receive the access requests
                        SelectedWeb.SetUseAccessRequestDefaultAndUpdate(false);
                        SelectedWeb.EnableRequestAccess(Emails[0]);
                    }
                }
                else
                {
                    if (Disabled)
                    {
                        // Disable requesting access
                        SelectedWeb.DisableRequestAccess();
                    }
                    else
                    {
                        // Enable requesting access and set it to the default owners group
                        // Code can be replaced by SelectedWeb.EnableRequestAccess(); once https://github.com/SharePoint/PnP-Sites-Core/pull/2533 has been accepted for merge.
                        SelectedWeb.SetUseAccessRequestDefaultAndUpdate(true);
                        SelectedWeb.Update();
                        SelectedWeb.Context.ExecuteQueryRetry();
                    }
                }
            }
        }
Exemple #27
0
        protected override void ExecuteCmdlet()
        {
            // Following code to handle desprecated parameter
            if (MyInvocation.BoundParameters.ContainsKey("FromSite"))
            {
                Scope = CustomActionScope.Site;
            }

            List <UserCustomAction> actions = new List <UserCustomAction>();

            if (Scope == CustomActionScope.All || Scope == CustomActionScope.Web)
            {
                actions.AddRange(SelectedWeb.GetCustomActions().Where(c => c.Location == "ScriptLink"));
            }
            if (Scope == CustomActionScope.All || Scope == CustomActionScope.Site)
            {
                actions.AddRange(ClientContext.Site.GetCustomActions().Where(c => c.Location == "ScriptLink"));
            }

            if (!actions.Any())
            {
                return;
            }

            foreach (var action in actions.Where(action => Force || ShouldContinue(string.Format(Resources.RemoveJavaScript0, action.Name), Resources.Confirm)))
            {
                switch (action.Scope)
                {
                case UserCustomActionScope.Web:
                    SelectedWeb.DeleteJsLink(Name);
                    break;

                case UserCustomActionScope.Site:
                    ClientContext.Site.DeleteJsLink(Name);
                    break;
                }
            }
        }
        protected override void ExecuteCmdlet()
        {
            if (SiteLogoUrl != null)
            {
                SelectedWeb.SiteLogoUrl = SiteLogoUrl;
                SelectedWeb.Update();
            }
            if (!string.IsNullOrEmpty(AlternateCssUrl))
            {
                SelectedWeb.AlternateCssUrl = AlternateCssUrl;
                SelectedWeb.Update();
            }
            if (!string.IsNullOrEmpty(Title))
            {
                SelectedWeb.Title = Title;
                SelectedWeb.Update();
            }

            if (!string.IsNullOrEmpty(Description))
            {
                SelectedWeb.Description = Description;
                SelectedWeb.Update();
            }

            if (!string.IsNullOrEmpty(MasterUrl))
            {
                SelectedWeb.MasterUrl = MasterUrl;
                SelectedWeb.Update();
            }

            if (!string.IsNullOrEmpty(CustomMasterUrl))
            {
                SelectedWeb.CustomMasterUrl = CustomMasterUrl;
                SelectedWeb.Update();
            }

            ClientContext.ExecuteQueryRetry();
        }
        protected override void ExecuteCmdlet()
        {
            var serverRelativeWebUrl = SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl);

            if (!ServerRelativePageUrl.ToLowerInvariant().StartsWith(serverRelativeWebUrl.ToLowerInvariant()))
            {
                ServerRelativePageUrl = UrlUtility.Combine(serverRelativeWebUrl, ServerRelativePageUrl);
            }


            var definitions = SelectedWeb.GetWebParts(ServerRelativePageUrl);

            if (Identity != null)
            {
                if (Identity.Id != Guid.Empty)
                {
                    var wpfound            = from wp in definitions where wp.Id == Identity.Id select wp;
                    var webPartDefinitions = wpfound as WebPartDefinition[] ?? wpfound.ToArray();
                    if (webPartDefinitions.Any())
                    {
                        WriteObject(webPartDefinitions.FirstOrDefault());
                    }
                }
                else if (!string.IsNullOrEmpty(Identity.Title))
                {
                    var wpfound            = from wp in definitions where wp.WebPart.Title == Identity.Title select wp;
                    var webPartDefinitions = wpfound as WebPartDefinition[] ?? wpfound.ToArray();
                    if (webPartDefinitions.Any())
                    {
                        WriteObject(webPartDefinitions.FirstOrDefault());
                    }
                }
            }
            else
            {
                WriteObject(definitions, true);
            }
        }
 protected override void ExecuteCmdlet()
 {
     if (Identity.Definition != null)
     {
         Identity.Definition.Delete();
     }
     else if (Identity.Id != Guid.Empty)
     {
         var definition = SelectedWeb.GetWorkflowDefinition(Identity.Id);
         if (definition != null)
         {
             definition.Delete();
         }
     }
     else if (!string.IsNullOrEmpty(Identity.Name))
     {
         var definition = SelectedWeb.GetWorkflowDefinition(Identity.Name);
         if (definition != null)
         {
             definition.Delete();
         }
     }
 }