diff --git a/Binaries/PnPPowerShellCommands15.msi b/Binaries/PnPPowerShellCommands15.msi index df581f00d..ac492ed4b 100644 Binary files a/Binaries/PnPPowerShellCommands15.msi and b/Binaries/PnPPowerShellCommands15.msi differ diff --git a/Binaries/PnPPowerShellCommands16.msi b/Binaries/PnPPowerShellCommands16.msi index a70b116ec..c798210d4 100644 Binary files a/Binaries/PnPPowerShellCommands16.msi and b/Binaries/PnPPowerShellCommands16.msi differ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b61ed8a5e..36a2be1a8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,7 +30,7 @@ Please see following page for additional insights on the model. ##Code contributions -In order to succesfully compile the PnP PowerShell solution you will _also_ have to download the [PnP-Sites-Core](https://github.com/OfficeDev/PnP-Sites-Core) repository and make the dev branch available. The PowerShell solution depends on it. In order to succesfully +In order to succesfully compile the PnP PowerShell solution you will _also_ have to download *and build in Visual Studio* the [PnP-Sites-Core](https://github.com/OfficeDev/PnP-Sites-Core) repository and make the dev branch available. The PowerShell solution depends on it. In order to succesfully compile it, make sure that PnP-Sites-Core is located at the same level as PnP-PowerShell. So: diff --git a/CmdletHelpGenerator/Program.cs b/CmdletHelpGenerator/Program.cs index e3a9304e6..903a72623 100644 --- a/CmdletHelpGenerator/Program.cs +++ b/CmdletHelpGenerator/Program.cs @@ -31,6 +31,8 @@ static void Main(string[] args) solutionDir = args[2]; generateMarkdown = true; } + + var doc = new XDocument(new XDeclaration("1.0", "UTF-8", string.Empty)); XNamespace ns = "http://msh"; @@ -48,13 +50,13 @@ static void Main(string[] args) var assembly = Assembly.LoadFrom(inFile); var types = assembly.GetTypes(); + // System.Diagnostics.Debugger.Launch(); + foreach (var t in types) { if (t.BaseType.Name == "SPOCmdlet" || t.BaseType.Name == "PSCmdlet" || t.BaseType.Name == "SPOWebCmdlet" || t.BaseType.Name == "SPOAdminCmdlet") { - //XElement examples = new XElement(command + "examples"); - var verb = string.Empty; var noun = string.Empty; var description = string.Empty; @@ -65,7 +67,7 @@ static void Main(string[] args) var attrs = t.GetCustomAttributes(); var examples = new List(); var relatedLinks = new List(); - //System.Attribute.GetCustomAttributes(t); + // Get info from attributes foreach (var attr in attrs) @@ -126,7 +128,8 @@ static void Main(string[] args) commandElement.Add(syntaxElement); // Store syntaxes in CmdletInfo structure (if not AllParameterSets), and also in all syntaxItems list - var fields = t.GetFields(); + var fields = GetFields(t); + //var fields = t.GetFields(); var syntaxItems = new List(); foreach (var field in fields) { @@ -347,138 +350,177 @@ static void Main(string[] args) // Markdown from CmdletInfo if (generateMarkdown) { - var originalMd = string.Empty; - var newMd = string.Empty; + GenerateMarkDown(toc, solutionDir, examples, cmdletInfo); + } + } - if (!string.IsNullOrEmpty(cmdletInfo.Verb) && !string.IsNullOrEmpty(cmdletInfo.Noun)) - { - string mdFilePath = string.Format("{0}\\Documentation\\{1}{2}.md", solutionDir, cmdletInfo.Verb, cmdletInfo.Noun); - toc.Add(cmdletInfo); + } + doc.Save(outFile); - if (System.IO.File.Exists(mdFilePath)) - { - originalMd = System.IO.File.ReadAllText(mdFilePath); + if (generateMarkdown) + { + CreateReadme(toc, solutionDir); + } - } - var docBuilder = new StringBuilder(); - - // Header + DirectoryInfo di = new DirectoryInfo(string.Format("{0}\\Documentation", solutionDir)); + var mdFiles = di.GetFiles("*.md"); + + // Clean up old MD files + foreach (var mdFile in mdFiles) + { + if (mdFile.Name.ToLowerInvariant() != "readme.md") + { + var index = toc.FindIndex(t => string.Format("{0}{1}.md", t.Verb, t.Noun) == mdFile.Name); + if (index == -1) + { + mdFile.Delete(); + } + } + } + } - docBuilder.AppendFormat("#{0}{1}", cmdletInfo.FullCommand, Environment.NewLine); + private static List GetFields(Type t) + { + var fieldInfoList = new List(); + foreach (var fieldInfo in t.GetFields()) + { + fieldInfoList.Add(fieldInfo); + } + if (t.BaseType != null && t.BaseType.BaseType != null) + { + fieldInfoList.AddRange(GetFields(t.BaseType.BaseType)); + } + return fieldInfoList; + } - // Body - - docBuilder.AppendFormat("{0}{1}", cmdletInfo.Description, Environment.NewLine); - docBuilder.AppendFormat("##Syntax{0}", Environment.NewLine); - foreach (var cmdletSyntax in cmdletInfo.Syntaxes.OrderBy(s => s.ParameterSetName)) - { - var syntaxText = new StringBuilder(); - syntaxText.AppendFormat("```powershell\r\n{0}", cmdletInfo.FullCommand); - foreach (var par in cmdletSyntax.Parameters.OrderBy(p => p.Position)) - { - syntaxText.Append(" "); - if (!par.Required) - { - syntaxText.Append("["); - } - if (par.Type == "SwitchParameter") - { - syntaxText.AppendFormat("-{0} [<{1}>]", par.Name, par.Type); - } - else - { - syntaxText.AppendFormat("-{0} <{1}>", par.Name, par.Type); - } - if (!par.Required) - { - syntaxText.Append("]"); - } - } - // Add All ParameterSet ones - docBuilder.Append(syntaxText); - docBuilder.AppendFormat("\n```\n\n\n"); - } + private static void CreateReadme(List toc, string solutionDir) + { + var originalMd = string.Empty; + var newMd = string.Empty; - if (!string.IsNullOrEmpty(cmdletInfo.DetailedDescription)) - { - docBuilder.Append("##Detailed Description\n"); - docBuilder.AppendFormat("{0}\n\n", cmdletInfo.DetailedDescription); - } - docBuilder.Append("##Parameters\n"); - docBuilder.Append("Parameter|Type|Required|Description\n"); - docBuilder.Append("---------|----|--------|-----------\n"); - foreach (var par in cmdletInfo.Parameters.OrderBy(x => x.Name)) - { - docBuilder.AppendFormat("|{0}|{1}|{2}|{3}|\n", par.Name, par.Type, par.Required ? "True" : "False", par.Description); - } - if (examples.Any()) - docBuilder.Append("##Examples\n"); - var examplesCount = 1; - foreach (var example in examples.OrderBy(e => e.SortOrder)) - { - docBuilder.AppendFormat("{0}\n", example.Introduction); - docBuilder.AppendFormat("###Example {0}\n", examplesCount); - docBuilder.AppendFormat("```powershell\n{0}\n```\n", example.Code); - docBuilder.AppendFormat("{0}\n", example.Remarks); - examplesCount++; - } + // Create the readme.md + var readmePath = string.Format("{0}\\Documentation\\readme.md", solutionDir); + if (System.IO.File.Exists(readmePath)) + { + originalMd = System.IO.File.ReadAllText(readmePath); + } + var docBuilder = new StringBuilder(); - newMd = docBuilder.ToString(); - DiffMatchPatch.diff_match_patch dmp = new DiffMatchPatch.diff_match_patch(); + docBuilder.AppendFormat("# Cmdlet Documentation #{0}", Environment.NewLine); + docBuilder.AppendFormat("Below you can find a list of all the available cmdlets. Many commands provide built-in help and examples. Retrieve the detailed help with {0}", Environment.NewLine); + docBuilder.AppendFormat("{0}```powershell{0}Get-Help Connect-SPOnline -Detailed{0}```{0}{0}", Environment.NewLine); - var diffResults = dmp.diff_main(newMd, originalMd); + // Get all unique categories + var categories = toc.Select(c => c.Category).Distinct(); - foreach (var result in diffResults) - { - if (result.operation != DiffMatchPatch.Operation.EQUAL) - { - System.IO.File.WriteAllText(mdFilePath, docBuilder.ToString()); - break; - } - } - } - } + foreach (var category in categories.OrderBy(c => c)) + { + docBuilder.AppendFormat("##{0}{1}", category, Environment.NewLine); + + docBuilder.AppendFormat("Cmdlet|Description{0}", Environment.NewLine); + docBuilder.AppendFormat(":-----|:----------{0}", Environment.NewLine); + foreach (var cmdletInfo in toc.Where(c => c.Category == category).OrderBy(c => c.Noun)) + { + var description = cmdletInfo.Description.Replace("\r\n", " "); + docBuilder.AppendFormat("**[{0}]({1}{2}.md)** |{3}{4}", cmdletInfo.FullCommand.Replace("-", "‑"), cmdletInfo.Verb, cmdletInfo.Noun, description, Environment.NewLine); } + } + + newMd = docBuilder.ToString(); + DiffMatchPatch.diff_match_patch dmp = new DiffMatchPatch.diff_match_patch(); + + var diffResults = dmp.diff_main(newMd, originalMd); + foreach (var result in diffResults) + { + if (result.operation != DiffMatchPatch.Operation.EQUAL) + { + System.IO.File.WriteAllText(readmePath, docBuilder.ToString()); + } } - doc.Save(outFile); + } - if (generateMarkdown) + private static void GenerateMarkDown(List toc, string solutionDir, List examples, CmdletInfo cmdletInfo) + { + var originalMd = string.Empty; + var newMd = string.Empty; + + if (!string.IsNullOrEmpty(cmdletInfo.Verb) && !string.IsNullOrEmpty(cmdletInfo.Noun)) { - var originalMd = string.Empty; - var newMd = string.Empty; + string mdFilePath = string.Format("{0}\\Documentation\\{1}{2}.md", solutionDir, cmdletInfo.Verb, cmdletInfo.Noun); + toc.Add(cmdletInfo); - // Create the readme.md - var readmePath = string.Format("{0}\\Documentation\\readme.md", solutionDir); - if (System.IO.File.Exists(readmePath)) + if (System.IO.File.Exists(mdFilePath)) { - originalMd = System.IO.File.ReadAllText(readmePath); + originalMd = System.IO.File.ReadAllText(mdFilePath); + } var docBuilder = new StringBuilder(); + // Header - docBuilder.AppendFormat("# Cmdlet Documentation #{0}", Environment.NewLine); - docBuilder.AppendFormat("Below you can find a list of all the available cmdlets. Many commands provide built-in help and examples. Retrieve the detailed help with {0}", Environment.NewLine); - docBuilder.AppendFormat("{0}```powershell{0}Get-Help Connect-SPOnline -Detailed{0}```{0}{0}", Environment.NewLine); + docBuilder.AppendFormat("#{0}{1}", cmdletInfo.FullCommand, Environment.NewLine); - // Get all unique categories - var categories = toc.Select(c => c.Category).Distinct(); + // Body - foreach (var category in categories.OrderBy(c => c)) + docBuilder.AppendFormat("{0}{1}", cmdletInfo.Description, Environment.NewLine); + docBuilder.AppendFormat("##Syntax{0}", Environment.NewLine); + foreach (var cmdletSyntax in cmdletInfo.Syntaxes.OrderBy(s => s.ParameterSetName)) { - docBuilder.AppendFormat("##{0}{1}", category, Environment.NewLine); - - docBuilder.AppendFormat("Cmdlet|Description{0}", Environment.NewLine); - docBuilder.AppendFormat(":-----|:----------{0}", Environment.NewLine); - foreach (var cmdletInfo in toc.Where(c => c.Category == category).OrderBy(c => c.Noun)) + var syntaxText = new StringBuilder(); + syntaxText.AppendFormat("```powershell\r\n{0}", cmdletInfo.FullCommand); + foreach (var par in cmdletSyntax.Parameters.OrderBy(p => p.Position)) { - var description = cmdletInfo.Description.Replace("\r\n", " "); - docBuilder.AppendFormat("**[{0}]({1}{2}.md)** |{3}{4}", cmdletInfo.FullCommand.Replace("-", "‑"), cmdletInfo.Verb, cmdletInfo.Noun, description, Environment.NewLine); + syntaxText.Append(" "); + if (!par.Required) + { + syntaxText.Append("["); + } + if (par.Type == "SwitchParameter") + { + syntaxText.AppendFormat("-{0} [<{1}>]", par.Name, par.Type); + } + else + { + syntaxText.AppendFormat("-{0} <{1}>", par.Name, par.Type); + } + if (!par.Required) + { + syntaxText.Append("]"); + } } + // Add All ParameterSet ones + docBuilder.Append(syntaxText); + docBuilder.AppendFormat("\n```\n\n\n"); + } + + if (!string.IsNullOrEmpty(cmdletInfo.DetailedDescription)) + { + docBuilder.Append("##Detailed Description\n"); + docBuilder.AppendFormat("{0}\n\n", cmdletInfo.DetailedDescription); + } + docBuilder.Append("##Parameters\n"); + docBuilder.Append("Parameter|Type|Required|Description\n"); + docBuilder.Append("---------|----|--------|-----------\n"); + foreach (var par in cmdletInfo.Parameters.OrderBy(x => x.Name)) + { + docBuilder.AppendFormat("|{0}|{1}|{2}|{3}|\n", par.Name, par.Type, par.Required ? "True" : "False", par.Description); + } + if (examples.Any()) + docBuilder.Append("##Examples\n"); + var examplesCount = 1; + foreach (var example in examples.OrderBy(e => e.SortOrder)) + { + docBuilder.AppendFormat("{0}\n", example.Introduction); + docBuilder.AppendFormat("###Example {0}\n", examplesCount); + docBuilder.AppendFormat("```powershell\n{0}\n```\n", example.Code); + docBuilder.AppendFormat("{0}\n", example.Remarks); + examplesCount++; } newMd = docBuilder.ToString(); + DiffMatchPatch.diff_match_patch dmp = new DiffMatchPatch.diff_match_patch(); var diffResults = dmp.diff_main(newMd, originalMd); @@ -487,23 +529,8 @@ static void Main(string[] args) { if (result.operation != DiffMatchPatch.Operation.EQUAL) { - System.IO.File.WriteAllText(readmePath, docBuilder.ToString()); - } - } - } - - DirectoryInfo di = new DirectoryInfo(string.Format("{0}\\Documentation", solutionDir)); - var mdFiles = di.GetFiles("*.md"); - - // Clean up old MD files - foreach (var mdFile in mdFiles) - { - if (mdFile.Name.ToLowerInvariant() != "readme.md") - { - var index = toc.FindIndex(t => string.Format("{0}{1}.md", t.Verb, t.Noun) == mdFile.Name); - if (index == -1) - { - mdFile.Delete(); + System.IO.File.WriteAllText(mdFilePath, docBuilder.ToString()); + break; } } } diff --git a/Commands/Base/ConnectSPOnline.cs b/Commands/Base/ConnectSPOnline.cs index f387e1e73..20bd9d0f9 100644 --- a/Commands/Base/ConnectSPOnline.cs +++ b/Commands/Base/ConnectSPOnline.cs @@ -67,6 +67,9 @@ public class ConnectSPOnline : PSCmdlet [Parameter(Mandatory = true, ParameterSetName = "Token", HelpMessage = "The Application Client Secret to use.")] public string AppSecret; + [Parameter(Mandatory = true, ParameterSetName = "Weblogin", HelpMessage = "If you want to connect to SharePoint with browser based login")] + public SwitchParameter UseWebLogin; + #if !CLIENTSDKV15 [Parameter(Mandatory = true, ParameterSetName = "NativeAAD", HelpMessage = "The Client ID of the Azure AD Application")] [Parameter(Mandatory = true, ParameterSetName = "AppOnlyAAD", HelpMessage = "The Client ID of the Azure AD Application")] @@ -102,6 +105,10 @@ protected override void ProcessRecord() { SPOnlineConnection.CurrentConnection = SPOnlineConnectionHelper.InstantiateSPOnlineConnection(new Uri(Url), Realm, AppId, AppSecret, Host, MinimalHealthScore, RetryCount, RetryWait, RequestTimeout, SkipTenantAdminCheck); } + else if(UseWebLogin) + { + SPOnlineConnection.CurrentConnection = SPOnlineConnectionHelper.InstantiateWebloginConnection(new Uri(Url), MinimalHealthScore, RetryCount, RetryWait, RequestTimeout, SkipTenantAdminCheck); + } else if (UseAdfs) { creds = GetCredentials(); diff --git a/Commands/Base/ExecuteSPOQuery.cs b/Commands/Base/ExecuteQuery.cs similarity index 100% rename from Commands/Base/ExecuteSPOQuery.cs rename to Commands/Base/ExecuteQuery.cs diff --git a/Commands/Base/GetContext.cs b/Commands/Base/GetContext.cs new file mode 100644 index 000000000..590fd32a9 --- /dev/null +++ b/Commands/Base/GetContext.cs @@ -0,0 +1,33 @@ +using System.Management.Automation; +using OfficeDevPnP.PowerShell.CmdletHelpAttributes; +using System; +using OfficeDevPnP.PowerShell.Commands.Properties; + +namespace OfficeDevPnP.PowerShell.Commands.Base +{ + [Cmdlet(VerbsCommon.Get, "SPOContext")] + [CmdletHelp("Returns a Client Side Object Model context", + Category = CmdletHelpCategory.Base)] + public class GetSPOContext : PSCmdlet + { + + protected override void BeginProcessing() + { + base.BeginProcessing(); + + if (SPOnlineConnection.CurrentConnection == null) + { + throw new InvalidOperationException(Resources.NoConnection); + } + if (SPOnlineConnection.CurrentConnection.Context == null) + { + throw new InvalidOperationException(Resources.NoConnection); + } + } + + protected override void ProcessRecord() + { + WriteObject(SPOnlineConnection.CurrentConnection.Context); + } + } +} diff --git a/Commands/Base/GetSPOContext.cs b/Commands/Base/GetSPOContext.cs deleted file mode 100644 index 3c5e13620..000000000 --- a/Commands/Base/GetSPOContext.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Management.Automation; -using OfficeDevPnP.PowerShell.CmdletHelpAttributes; - -namespace OfficeDevPnP.PowerShell.Commands.Base -{ - [Cmdlet(VerbsCommon.Get, "SPOContext")] - [CmdletHelp("Returns a Client Side Object Model context", - Category = CmdletHelpCategory.Base)] - public class GetSPOContext : PSCmdlet - { - protected override void ProcessRecord() - { - WriteObject(SPOnlineConnection.CurrentConnection.Context); - } - } -} diff --git a/Commands/Base/PipeBinds/ListItemPipeBind.cs b/Commands/Base/PipeBinds/ListItemPipeBind.cs new file mode 100644 index 000000000..c117356d5 --- /dev/null +++ b/Commands/Base/PipeBinds/ListItemPipeBind.cs @@ -0,0 +1,69 @@ +using Microsoft.SharePoint.Client; +using System; + +namespace OfficeDevPnP.PowerShell.Commands.Base.PipeBinds +{ + public sealed class ListItemPipeBind + { + private readonly ListItem _item; + private readonly uint _id; + + public ListItemPipeBind() + { + _item = null; + _id = uint.MinValue; + } + + public ListItemPipeBind(ListItem item) + { + _item = item; + } + + public ListItemPipeBind(string id) + { + uint uintId; + + if (uint.TryParse(id, out uintId)) + { + _id = uintId; + } + else + { + _id = uint.MinValue; + } + } + + public ListItem Item + { + get + { + return _item; + } + } + + public uint Id + { + get { return _id; } + } + + internal ListItem GetListItem(List list) + { + ListItem item = null; + if (_id != uint.MinValue) + { + item = list.GetItemById((int)_id); + } + if (item == null && _item != null) + { + item = _item; + } + + if (item != null) + { + list.Context.Load(item); + list.Context.ExecuteQueryRetry(); + } + return item; + } + } +} diff --git a/Commands/Base/SPOWebCmdlet.cs b/Commands/Base/SPOWebCmdlet.cs index 39d7c425d..be15cfd5b 100644 --- a/Commands/Base/SPOWebCmdlet.cs +++ b/Commands/Base/SPOWebCmdlet.cs @@ -61,6 +61,7 @@ private Web GetWeb() web = ClientContext.Web; } + SPOnlineConnection.CurrentConnection.Context.ExecuteQueryRetry(); return web; } diff --git a/Commands/Base/SPOnlineConnectionHelper.cs b/Commands/Base/SPOnlineConnectionHelper.cs index 616e0a37f..c3a336d65 100644 --- a/Commands/Base/SPOnlineConnectionHelper.cs +++ b/Commands/Base/SPOnlineConnectionHelper.cs @@ -58,6 +58,7 @@ internal static SPOnlineConnection InstantiateSPOnlineConnection(Uri url, string return new SPOnlineConnection(context, connectionType, minimalHealthScore, retryCount, retryWait, null, url.ToString()); } + #if !CLIENTSDKV15 internal static SPOnlineConnection InitiateAzureADNativeApplicationConnection(Uri url, string clientId, Uri redirectUri, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, bool skipAdminCheck = false) { @@ -106,6 +107,34 @@ internal static SPOnlineConnection InitiateAzureADAppOnlyConnection(Uri url, str } #endif + internal static SPOnlineConnection InstantiateWebloginConnection(Uri url, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, bool skipAdminCheck = false) + { + var authManager = new Core.AuthenticationManager(); + + var context = authManager.GetWebLoginClientContext(url.ToString()); + + if (context != null) + { + context.ApplicationName = Properties.Resources.ApplicationName; + context.RequestTimeout = requestTimeout; + var connectionType = ConnectionType.OnPrem; + if (url.Host.ToUpperInvariant().EndsWith("SHAREPOINT.COM")) + { + connectionType = ConnectionType.O365; + } + if (skipAdminCheck == false) + { + if (IsTenantAdminSite(context)) + { + connectionType = ConnectionType.TenantAdmin; + } + } + + return new SPOnlineConnection(context, connectionType, minimalHealthScore, retryCount, retryWait, null, url.ToString()); + } + throw new Exception("Error establishing a connection, context is null"); + } + internal static SPOnlineConnection InstantiateSPOnlineConnection(Uri url, PSCredential credentials, PSHost host, bool currentCredentials, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, bool skipAdminCheck = false) { ClientContext context = new ClientContext(url.AbsoluteUri); diff --git a/Commands/Base/SetContext.cs b/Commands/Base/SetContext.cs new file mode 100644 index 000000000..5947a65f3 --- /dev/null +++ b/Commands/Base/SetContext.cs @@ -0,0 +1,28 @@ +using System.Management.Automation; +using OfficeDevPnP.PowerShell.CmdletHelpAttributes; +using Microsoft.SharePoint.Client; + +namespace OfficeDevPnP.PowerShell.Commands.Base +{ + [Cmdlet(VerbsCommon.Set, "SPOContext")] + [CmdletHelp("Sets the Client Context to use by the cmdlets", + Category = CmdletHelpCategory.Base)] + [CmdletExample( + Code = @"PS:> Connect-SPOnline -Url $siteAurl -Credentials $credentials +PS:> $ctx = Get-SPOContext +PS:> Get-SPOList # returns the lists from site specified with $siteAurl +PS:> Connect-SPOnline -Url $siteBurl -Credentials $credentials +PS:> Get-SPOList # returns the lists from the site specified with $siteBurl +PS:> Set-SPOContext -Context $ctx # switch back to site A +PS:> Get-SPOList # returns the lists from site A", SortOrder = 1)] + public class SetContext : PSCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true, Position = 1, HelpMessage = "The ClientContext to set")] + public ClientContext Context; + + protected override void ProcessRecord() + { + SPOnlineConnection.CurrentConnection.Context = Context; + } + } +} diff --git a/Commands/Branding/AddCustomAction.cs b/Commands/Branding/AddCustomAction.cs index 64bde92da..f6a164940 100644 --- a/Commands/Branding/AddCustomAction.cs +++ b/Commands/Branding/AddCustomAction.cs @@ -32,7 +32,7 @@ public class AddCustomAction : SPOWebCmdlet [Parameter(Mandatory = true)] public string Location = string.Empty; - [Parameter(Mandatory = false)] + [Parameter(Mandatory = false, HelpMessage = "Sequence of this CustomAction being injected. Use when you have a specific sequence with which to have multple CustomActions being added to the page.")] public int Sequence = 0; [Parameter(Mandatory = false)] @@ -53,10 +53,9 @@ public class AddCustomAction : SPOWebCmdlet [Parameter(Mandatory = false)] public UserCustomActionRegistrationType RegistrationType; - [Parameter(Mandatory = false)] + [Parameter(Mandatory = false, HelpMessage = "The scope of the CustomAction to add to. Either Web or Site, defaults to Web. All is not valid for this command.")] public CustomActionScope Scope = CustomActionScope.Web; - protected override void ExecuteCmdlet() { var permissions = new BasePermissions(); @@ -84,14 +83,20 @@ protected override void ExecuteCmdlet() Rights = permissions }; - if (Scope == CustomActionScope.Web) + switch (Scope) { - SelectedWeb.AddCustomAction(ca); - } - else - { - ClientContext.Site.AddCustomAction(ca); - } + case CustomActionScope.Web: + SelectedWeb.AddCustomAction(ca); + break; + + case CustomActionScope.Site: + ClientContext.Site.AddCustomAction(ca); + break; + + case CustomActionScope.All: + WriteWarning("CustomActionScope All is not supported for adding CustomActions"); + break; + } } } } diff --git a/Commands/Branding/AddJavaScriptBlock.cs b/Commands/Branding/AddJavaScriptBlock.cs index fdfa56673..cc57dc118 100644 --- a/Commands/Branding/AddJavaScriptBlock.cs +++ b/Commands/Branding/AddJavaScriptBlock.cs @@ -27,7 +27,7 @@ public class AddJavaScriptBlock : SPOWebCmdlet [Alias("AddToSite")] public SwitchParameter SiteScoped; - [Parameter(Mandatory = false, HelpMessage = "The scope of the script to add to. Either Web or Site, defaults to Web.")] + [Parameter(Mandatory = false, HelpMessage = "The scope of the script to add to. Either Web or Site, defaults to Web. All is not valid for this command.")] public CustomActionScope Scope = CustomActionScope.Web; protected override void ExecuteCmdlet() diff --git a/Commands/Branding/AddJavaScriptLink.cs b/Commands/Branding/AddJavaScriptLink.cs index 44facb422..fb1fd0f4c 100644 --- a/Commands/Branding/AddJavaScriptLink.cs +++ b/Commands/Branding/AddJavaScriptLink.cs @@ -9,15 +9,22 @@ namespace OfficeDevPnP.PowerShell.Commands [Cmdlet(VerbsCommon.Add, "SPOJavaScriptLink")] [CmdletHelp("Adds a link to a JavaScript file to a web or sitecollection", Category = CmdletHelpCategory.Branding)] + [CmdletExample(Code = "PS:> Add-SPOJavaScriptLink -Name jQuery -Url https://code.jquery.com/jquery.min.js -Sequence 9999 -Scope Site", + Remarks = "Injects a reference to the latest v1 series jQuery library to all pages within the current site collection under the name jQuery and at order 9999", + SortOrder = 1)] + [CmdletExample(Code = "PS:> Add-SPOJavaScriptLink -Name jQuery -Url https://code.jquery.com/jquery.min.js", + Remarks = "Injects a reference to the latest v1 series jQuery library to all pages within the current web under the name jQuery", + SortOrder = 2)] public class AddJavaScriptLink : SPOWebCmdlet { - [Parameter(Mandatory = true)] - public string Key = string.Empty; + [Parameter(Mandatory = true, HelpMessage = "Name under which to register the JavaScriptLink")] + [Alias("Key")] + public string Name = string.Empty; - [Parameter(Mandatory = true)] + [Parameter(Mandatory = true, HelpMessage = "URL to the JavaScript file to inject")] public string[] Url = null; - [Parameter(Mandatory = false)] + [Parameter(Mandatory = false, HelpMessage = "Sequence of this JavaScript being injected. Use when you have a specific sequence with which to have JavaScript files being added to the page. I.e. jQuery library first and then jQueryUI.")] public int Sequence = 0; [Parameter(Mandatory = false)] @@ -25,7 +32,7 @@ public class AddJavaScriptLink : SPOWebCmdlet [Alias("AddToSite")] public SwitchParameter SiteScoped; - [Parameter(Mandatory = false)] + [Parameter(Mandatory = false, HelpMessage = "Defines if this JavaScript file will be injected to every page within the current site collection or web. All is not allowed in for this command. Default is web.")] public CustomActionScope Scope = CustomActionScope.Web; protected override void ExecuteCmdlet() @@ -42,14 +49,19 @@ protected override void ExecuteCmdlet() setScope = Scope; } - if (setScope == CustomActionScope.Web) + switch (setScope) { - SelectedWeb.AddJsLink(Key, Url, Sequence); - } - else - { - var site = ClientContext.Site; - site.AddJsLink(Key, Url, Sequence); + case CustomActionScope.Web: + SelectedWeb.AddJsLink(Name, Url, Sequence); + break; + + case CustomActionScope.Site: + ClientContext.Site.AddJsLink(Name, Url, Sequence); + break; + + case CustomActionScope.All: + WriteWarning("CustomActionScope All is not supported for adding JavaScriptLinks"); + break; } } } diff --git a/Commands/Branding/ApplyProvisioningTemplate.cs b/Commands/Branding/ApplyProvisioningTemplate.cs index 299a0594b..0f3a4095c 100644 --- a/Commands/Branding/ApplyProvisioningTemplate.cs +++ b/Commands/Branding/ApplyProvisioningTemplate.cs @@ -21,28 +21,28 @@ namespace OfficeDevPnP.PowerShell.Commands.Branding [CmdletHelp("Applies a provisioning template to a web", Category = CmdletHelpCategory.Branding)] [CmdletExample( - Code = @" - PS:> Apply-SPOProvisioningTemplate -Path template.xml -", + Code = @"PS:> Apply-SPOProvisioningTemplate -Path template.xml", Remarks = @"Applies a provisioning template in XML format to the current web. ", SortOrder = 1)] [CmdletExample( - Code = @" - PS:> Apply-SPOProvisioningTemplate -Path template.xml -ResourceFolder c:\provisioning\resources -", + Code = @"PS:> Apply-SPOProvisioningTemplate -Path template.xml -ResourceFolder c:\provisioning\resources", Remarks = @"Applies a provisioning template in XML format to the current web. Any resources like files that are referenced in the template will be retrieved from the folder as specified with the ResourceFolder parameter. ", SortOrder = 2)] [CmdletExample( - Code = @" - PS:> Apply-SPOProvisioningTemplate -Path template.xml -Parameters @{""ListTitle""=""Projects"";""parameter2""=""a second value""} -", + Code = @"PS:> Apply-SPOProvisioningTemplate -Path template.xml -Parameters @{""ListTitle""=""Projects"";""parameter2""=""a second value""}", Remarks = @"Applies a provisioning template in XML format to the current web. It will populate the parameter in the template the values as specified and in the template you can refer to those values with the {parameter:} token. For instance with the example above, specifying {parameter:ListTitle} in your template will translate to 'Projects' when applying the template. These tokens can be used in most string values in a template.", SortOrder = 3)] + + [CmdletExample( + Code = @"PS:> Apply-SPOProvisioningTemplate -Path template.xml -Handlers Lists, SiteSecurity", + Remarks = @"Applies a provisioning template in XML format to the current web. It will only apply the lists and site security part of the template.", + SortOrder = 4)] + public class ApplyProvisioningTemplate : SPOWebCmdlet { [Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true, HelpMessage = "Path to the xml file containing the provisioning template.")] @@ -57,6 +57,9 @@ public class ApplyProvisioningTemplate : SPOWebCmdlet [Parameter(Mandatory = false, HelpMessage = "Allows you to specify parameters that can be referred to in the template by means of the {parameter:} token. See examples on how to use this parameter.")] public Hashtable Parameters; + [Parameter(Mandatory = false, HelpMessage = "Allows you to only process a specific part of the template. Notice that this might fail, as some of the handlers require other artifacts in place if they are not part of what your applying.")] + public Handlers Handlers; + protected override void ExecuteCmdlet() { SelectedWeb.EnsureProperty(w => w.Url); @@ -110,6 +113,11 @@ protected override void ExecuteCmdlet() var applyingInformation = new ProvisioningTemplateApplyingInformation(); + if (this.MyInvocation.BoundParameters.ContainsKey("Handlers")) + { + applyingInformation.HandlersToProcess = Handlers; + } + applyingInformation.ProgressDelegate = (message, step, total) => { WriteProgress(new ProgressRecord(0, string.Format("Applying template to {0}", SelectedWeb.Url), message) { PercentComplete = (100 / total) * step }); diff --git a/Commands/Branding/GetCustomAction.cs b/Commands/Branding/GetCustomAction.cs index 01438fb76..a4f9f76ab 100644 --- a/Commands/Branding/GetCustomAction.cs +++ b/Commands/Branding/GetCustomAction.cs @@ -13,23 +13,23 @@ namespace OfficeDevPnP.PowerShell.Commands Category = CmdletHelpCategory.Branding)] public class GetCustomAction : SPOWebCmdlet { - [Parameter(Mandatory = false)] + [Parameter(Mandatory = false, HelpMessage = "Identity of the CustomAction to return. Omit to return all CustomActions.")] public GuidPipeBind Identity; - [Parameter(Mandatory = false)] + [Parameter(Mandatory = false, HelpMessage = "Scope of the CustomAction, either Web, Site or All to return both")] public CustomActionScope Scope = CustomActionScope.Web; protected override void ExecuteCmdlet() { - List actions = null; + List actions = new List(); - if (Scope == CustomActionScope.Web) + if (Scope == CustomActionScope.All || Scope == CustomActionScope.Web) { - actions = SelectedWeb.GetCustomActions().ToList(); + actions.AddRange(SelectedWeb.GetCustomActions()); } - else + if (Scope == CustomActionScope.All || Scope == CustomActionScope.Site) { - actions = ClientContext.Site.GetCustomActions().ToList(); + actions.AddRange(ClientContext.Site.GetCustomActions()); } if (Identity != null) diff --git a/Commands/Branding/GetJavaScriptLink.cs b/Commands/Branding/GetJavaScriptLink.cs index 0fc4c3004..19d075ad4 100644 --- a/Commands/Branding/GetJavaScriptLink.cs +++ b/Commands/Branding/GetJavaScriptLink.cs @@ -11,26 +11,38 @@ namespace OfficeDevPnP.PowerShell.Commands [Cmdlet(VerbsCommon.Get, "SPOJavaScriptLink")] [CmdletHelp("Returns all or a specific custom action(s) with location type ScriptLink", Category = CmdletHelpCategory.Branding)] + [CmdletExample(Code = "PS:> Get-SPOJavaScriptLink", + Remarks = "Returns all web and site scoped JavaScriptLinks", + SortOrder = 1)] + [CmdletExample(Code = "PS:> Get-SPOJavaScriptLink -Scope Web", + Remarks = "Returns all site scoped JavaScriptLinks", + SortOrder = 2)] + [CmdletExample(Code = "PS:> Get-SPOJavaScriptLink -Scope Site", + Remarks = "Returns all web scoped JavaScriptLinks", + SortOrder = 3)] + [CmdletExample(Code = "PS:> Get-SPOJavaScriptLink -Name Test", + Remarks = "Returns the JavaScriptLink named Test", + SortOrder = 4)] public class GetJavaScriptLink : SPOWebCmdlet { [Parameter(Mandatory = false, ValueFromPipeline = true, Position = 0, HelpMessage = "Name of the Javascript link. Omit this parameter to retrieve all script links")] [Alias("Key")] public string Name = string.Empty; - [Parameter(Mandatory = false, HelpMessage = "Scope of the action, either Web (default) or Site")] + [Parameter(Mandatory = false, HelpMessage = "Scope of the action, either Web, Site or All to return both")] public CustomActionScope Scope = CustomActionScope.Web; protected override void ExecuteCmdlet() { - IEnumerable actions = null; + List actions = new List(); - if (Scope == CustomActionScope.Web) + if (Scope == CustomActionScope.All || Scope == CustomActionScope.Web) { - actions = SelectedWeb.GetCustomActions().Where(c => c.Location == "ScriptLink"); + actions.AddRange(SelectedWeb.GetCustomActions().Where(c => c.Location == "ScriptLink")); } - else + if (Scope == CustomActionScope.All || Scope == CustomActionScope.Site) { - actions = ClientContext.Site.GetCustomActions().Where(c => c.Location == "ScriptLink"); + actions.AddRange(ClientContext.Site.GetCustomActions().Where(c => c.Location == "ScriptLink")); } if (!string.IsNullOrEmpty(Name)) @@ -40,7 +52,7 @@ protected override void ExecuteCmdlet() } else { - WriteObject(actions,true); + WriteObject(actions, true); } } } diff --git a/Commands/Branding/GetProvisioningTemplate.cs b/Commands/Branding/GetProvisioningTemplate.cs index 1d16b027a..5b55a7766 100644 --- a/Commands/Branding/GetProvisioningTemplate.cs +++ b/Commands/Branding/GetProvisioningTemplate.cs @@ -24,35 +24,30 @@ namespace OfficeDevPnP.PowerShell.Commands.Branding [CmdletHelp("Generates a provisioning template from a web", Category = CmdletHelpCategory.Branding)] [CmdletExample( - Code = @" - PS:> Get-SPOProvisioningTemplate -Out template.xml -", + Code = @"PS:> Get-SPOProvisioningTemplate -Out template.xml", Remarks = "Extracts a provisioning template in XML format from the current web.", SortOrder = 1)] [CmdletExample( -Code = @" - PS:> Get-SPOProvisioningTemplate -Out template.xml -Schema V201503 -", -Remarks = "Extracts a provisioning template in XML format from the current web and saves it in the V201503 version of the schema.", -SortOrder = 2)] + Code = @"PS:> Get-SPOProvisioningTemplate -Out template.xml -Schema V201503", + Remarks = "Extracts a provisioning template in XML format from the current web and saves it in the V201503 version of the schema.", + SortOrder = 2)] [CmdletExample( - Code = @" - PS:> Get-SPOProvisioningTemplate -Out template.xml -IncludeAllTermGroups -", - Remarks = "Extracts a provisioning template in XML format from the current web and includes all term groups, term sets and terms from the Managed Metadata Service Taxonomy.", - SortOrder = 3)] + Code = @"PS:> Get-SPOProvisioningTemplate -Out template.xml -IncludeAllTermGroups", + Remarks = "Extracts a provisioning template in XML format from the current web and includes all term groups, term sets and terms from the Managed Metadata Service Taxonomy.", + SortOrder = 3)] [CmdletExample( - Code = @" - PS:> Get-SPOProvisioningTemplate -Out template.xml -IncludeSiteCollectionTermGroup -", - Remarks = "Extracts a provisioning template in XML format from the current web and includes the term group currently (if set) assigned to the site collection.", - SortOrder = 4)] + Code = @"PS:> Get-SPOProvisioningTemplate -Out template.xml -IncludeSiteCollectionTermGroup", + Remarks = "Extracts a provisioning template in XML format from the current web and includes the term group currently (if set) assigned to the site collection.", + SortOrder = 4)] [CmdletExample( -Code = @" - PS:> Get-SPOProvisioningTemplate -Out template.xml -PersistComposedLookFiles -", -Remarks = "Extracts a provisioning template in XML format from the current web and saves the files that make up the composed look to the same folder as where the template is saved.", -SortOrder = 5)] + Code = @"PS:> Get-SPOProvisioningTemplate -Out template.xml -PersistComposedLookFiles", + Remarks = "Extracts a provisioning template in XML format from the current web and saves the files that make up the composed look to the same folder as where the template is saved.", + SortOrder = 5)] + [CmdletExample( + Code = @"PS:> Get-SPOProvisioningTemplate -Out template.xml -Handlers Lists, SiteSecurity", + Remarks = "Extracts a provisioning template in XML format from the current web, but only processes lists and site security when generating the template.", + SortOrder = 5)] + public class GetProvisioningTemplate : SPOWebCmdlet { [Parameter(Mandatory = false, Position = 0, HelpMessage = "Filename to write to, optionally including full path")] @@ -70,7 +65,11 @@ public class GetProvisioningTemplate : SPOWebCmdlet [Parameter(Mandatory = false, HelpMessage = "If specified all site groups will be included.")] public SwitchParameter IncludeSiteGroups; + [Parameter(Mandatory = false, HelpMessage = "If specified the files used for masterpages, sitelogo, alternate CSS and the files that make up the composed look will be saved.")] + public SwitchParameter PersistBrandingFiles; + [Parameter(Mandatory = false, HelpMessage = "If specified the files making up the composed look (background image, font file and color file) will be saved.")] + [Obsolete("Use PersistBrandingFiles instead.")] public SwitchParameter PersistComposedLookFiles; [Parameter(Mandatory = false, HelpMessage = "Overwrites the output file if it exists.")] @@ -83,10 +82,12 @@ public class GetProvisioningTemplate : SPOWebCmdlet [Parameter(Mandatory = false)] public System.Text.Encoding Encoding = System.Text.Encoding.Unicode; + [Parameter(Mandatory = false, HelpMessage = "Allows you to only process a specific type of artifact in the site. Notice that this might result in a non-working template, as some of the handlers require other artifacts in place if they are not part of what your extracting.")] + public Handlers Handlers; + protected override void ExecuteCmdlet() { - if (!string.IsNullOrEmpty(Out)) { if (!Path.IsPathRooted(Out)) @@ -123,9 +124,12 @@ private string GetProvisioningTemplateXML(XMLPnPSchemaVersion schema, string pat var creationInformation = new ProvisioningTemplateCreationInformation(SelectedWeb); + if (this.MyInvocation.BoundParameters.ContainsKey("Handlers")) + { + creationInformation.HandlersToProcess = Handlers; + } - - creationInformation.PersistComposedLookFiles = PersistComposedLookFiles; + creationInformation.PersistBrandingFiles = PersistBrandingFiles || PersistComposedLookFiles; creationInformation.IncludeSiteGroups = IncludeSiteGroups; creationInformation.FileConnector = new FileSystemConnector(path, ""); @@ -192,6 +196,11 @@ private string GetProvisioningTemplateXML(XMLPnPSchemaVersion schema, string pat formatter = XMLPnPSchemaFormatter.GetSpecificFormatter(XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_08); break; } + case XMLPnPSchemaVersion.V201512: + { + formatter = XMLPnPSchemaFormatter.GetSpecificFormatter(XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_12); + break; + } } var _outputStream = formatter.ToFormattedTemplate(template); StreamReader reader = new StreamReader(_outputStream); diff --git a/Commands/Branding/NewProvisioningTemplateFromFolder.cs b/Commands/Branding/NewProvisioningTemplateFromFolder.cs index c149c31d1..7ab750c88 100644 --- a/Commands/Branding/NewProvisioningTemplateFromFolder.cs +++ b/Commands/Branding/NewProvisioningTemplateFromFolder.cs @@ -8,6 +8,7 @@ using System.IO; using System.Linq; using System.Management.Automation; +using System.Xml.Linq; namespace OfficeDevPnP.PowerShell.Commands.Branding { @@ -73,6 +74,9 @@ public class NewProvisioningTemplateFromFolder : SPOWebCmdlet [Parameter(Mandatory = false, Position = 1, HelpMessage = "The schema of the output to use, defaults to the latest schema")] public XMLPnPSchemaVersion Schema = XMLPnPSchemaVersion.LATEST; + [Parameter(Mandatory = false, HelpMessage = "If specified, the output will only contain the element. This allows the output to be included in another template.")] + public SwitchParameter AsIncludeFile; + [Parameter(Mandatory = false, HelpMessage = "Overwrites the output file if it exists.")] public SwitchParameter Force; @@ -114,20 +118,57 @@ protected override void ExecuteCmdlet() var xml = GetFiles(Schema, new FileInfo(Out).DirectoryName, Folder, ct != null ? ct.StringId : null); + if(AsIncludeFile) + { + XElement xElement = XElement.Parse(xml); + // Get the Files Element + XNamespace pnp = XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_12; + + var filesElement = xElement.Descendants(pnp + "Files").FirstOrDefault(); + + if (filesElement != null) + { + xml = filesElement.ToString(); + } + } System.IO.File.WriteAllText(Out, xml, Encoding); } } else { var xml = GetFiles(Schema, new FileInfo(Out).DirectoryName, Folder, ct != null ? ct.StringId : null); + if (AsIncludeFile) + { + XElement xElement = XElement.Parse(xml); + // Get the Files Element + XNamespace pnp = XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_12; + + var filesElement = xElement.Descendants(pnp + "Files").FirstOrDefault(); + if (filesElement != null) + { + xml = filesElement.ToString(); + } + } System.IO.File.WriteAllText(Out, xml, Encoding); } } else { var xml = GetFiles(Schema, SessionState.Path.CurrentFileSystemLocation.Path, Folder, ct != null ? ct.StringId : null); + if (AsIncludeFile) + { + XElement xElement = XElement.Parse(xml); + // Get the Files Element + XNamespace pnp = XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_12; + + var filesElement = xElement.Descendants(pnp + "Files").FirstOrDefault(); + if (filesElement != null) + { + xml = filesElement.ToString(); + } + } WriteObject(xml); } diff --git a/Commands/Branding/RemoveCustomAction.cs b/Commands/Branding/RemoveCustomAction.cs index 550339393..eb80eb074 100644 --- a/Commands/Branding/RemoveCustomAction.cs +++ b/Commands/Branding/RemoveCustomAction.cs @@ -12,13 +12,13 @@ namespace OfficeDevPnP.PowerShell.Commands Category = CmdletHelpCategory.Branding)] public class RemoveCustomAction : SPOWebCmdlet { - [Parameter(Mandatory = true, Position=0, ValueFromPipeline=true)] + [Parameter(Mandatory = true, Position=0, ValueFromPipeline=true, HelpMessage = "The identifier of the CustomAction that needs to be removed")] public GuidPipeBind Identity; - [Parameter(Mandatory = false)] + [Parameter(Mandatory = false, HelpMessage = "Define if the CustomAction is to be found at the web or site collection scope. Specify All to allow deletion from either web or site collection.")] public CustomActionScope Scope = CustomActionScope.Web; - [Parameter(Mandatory = false)] + [Parameter(Mandatory = false, HelpMessage = "Use the -Force flag to bypass the confirmation question")] public SwitchParameter Force; protected override void ExecuteCmdlet() @@ -27,11 +27,11 @@ protected override void ExecuteCmdlet() { if (Force || ShouldContinue(Resources.RemoveCustomAction, Resources.Confirm)) { - if (Scope == CustomActionScope.Web) + if (Scope == CustomActionScope.All || Scope == CustomActionScope.Web) { SelectedWeb.DeleteCustomAction(Identity.Id); } - else + if (Scope == CustomActionScope.All || Scope == CustomActionScope.Site) { ClientContext.Site.DeleteCustomAction(Identity.Id); } diff --git a/Commands/Branding/RemoveJavaScriptLink.cs b/Commands/Branding/RemoveJavaScriptLink.cs index e2508e24f..979ebbc19 100644 --- a/Commands/Branding/RemoveJavaScriptLink.cs +++ b/Commands/Branding/RemoveJavaScriptLink.cs @@ -5,15 +5,25 @@ using OfficeDevPnP.PowerShell.Commands.Enums; using Resources = OfficeDevPnP.PowerShell.Commands.Properties.Resources; using System; +using System.Collections.Generic; namespace OfficeDevPnP.PowerShell.Commands { [Cmdlet(VerbsCommon.Remove, "SPOJavaScriptLink", SupportsShouldProcess = true)] [CmdletHelp("Removes a JavaScript link or block from a web or sitecollection", Category = CmdletHelpCategory.Branding)] + [CmdletExample(Code = "PS:> Remove-SPOJavaScriptLink -Name jQuery", + Remarks = "Removes the injected JavaScript file with the name jQuery from the current web after confirmation", + SortOrder = 1)] + [CmdletExample(Code = "PS:> Remove-SPOJavaScriptLink -Name jQuery -Scope Site", + Remarks = "Removes the injected JavaScript file with the name jQuery from the current site collection after confirmation", + SortOrder = 2)] + [CmdletExample(Code = "PS:> Remove-SPOJavaScriptLink -Name jQuery -Scope Site -Force", + Remarks = "Removes the injected JavaScript file with the name jQuery from the current site collection and will not ask for confirmation", + SortOrder = 3)] public class RemoveJavaScriptLink : SPOWebCmdlet { - [Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "Name of the Javascript link. Omit this parameter to retrieve all script links")] + [Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "Name of the JavaScriptLink to remove")] [Alias("Key")] public string Name = string.Empty; @@ -21,41 +31,44 @@ public class RemoveJavaScriptLink : SPOWebCmdlet [Obsolete("Use Scope parameter")] public SwitchParameter FromSite; - [Parameter(Mandatory = false)] + [Parameter(Mandatory = false, HelpMessage = "Use the -Force flag to bypass the confirmation question")] public SwitchParameter Force; - [Parameter(Mandatory = false)] + [Parameter(Mandatory = false, HelpMessage = "Define if the JavaScriptLink is to be found at the web or site collection scope. Specify All to allow deletion from either web or site collection.")] public CustomActionScope Scope = CustomActionScope.Web; protected override void ExecuteCmdlet() { - // Following code to handle desprecated parameter - CustomActionScope setScope; - if (MyInvocation.BoundParameters.ContainsKey("FromSite")) { - setScope = CustomActionScope.Site; + Scope = CustomActionScope.Site; + } + + List actions = new List(); + + if (Scope == CustomActionScope.All || Scope == CustomActionScope.Web) + { + actions.AddRange(SelectedWeb.GetCustomActions().Where(c => c.Location == "ScriptLink")); } - else + if (Scope == CustomActionScope.All || Scope == CustomActionScope.Site) { - setScope = Scope; + actions.AddRange(ClientContext.Site.GetCustomActions().Where(c => c.Location == "ScriptLink")); } - var action = setScope == CustomActionScope.Web ? SelectedWeb.GetCustomActions().FirstOrDefault(c => c.Name == Name) : ClientContext.Site.GetCustomActions().FirstOrDefault(c => c.Name == Name); - if (action != null) + if (!actions.Any()) return; + + foreach (var action in actions.Where(action => Force || ShouldContinue(string.Format(Resources.RemoveJavaScript0, action.Name), Resources.Confirm))) { - if (Force || ShouldContinue(string.Format(Resources.RemoveJavaScript0, action.Name), Resources.Confirm)) + switch (action.Scope) { - if (setScope == CustomActionScope.Web) - { + case UserCustomActionScope.Web: SelectedWeb.DeleteJsLink(Name); - } - else - { - var site = ClientContext.Site; - site.DeleteJsLink(Name); - } + break; + + case UserCustomActionScope.Site: + ClientContext.Site.DeleteJsLink(Name); + break; } } } diff --git a/Commands/DocumentSets/GetDocumentSetTemplate.cs b/Commands/DocumentSets/GetDocumentSetTemplate.cs index a62862f77..b6a297b16 100644 --- a/Commands/DocumentSets/GetDocumentSetTemplate.cs +++ b/Commands/DocumentSets/GetDocumentSetTemplate.cs @@ -17,9 +17,11 @@ namespace OfficeDevPnP.PowerShell.Commands.DocumentSets Category = CmdletHelpCategory.DocumentSets)] [CmdletExample( Code = @"PS:> Get-SPODocumentSetTemplate -Identity ""Test Document Set""", + Remarks = @"This will get the document set template with the name ""Test Document Set""", SortOrder = 1)] [CmdletExample( Code = @"PS:> Get-SPODocumentSetTemplate -Identity ""0x0120D520005DB65D094035A241BAC9AF083F825F3B""", + Remarks = @"This will get the document set template with the id ""0x0120D520005DB65D094035A241BAC9AF083F825F3B""", SortOrder = 2)] public class GetDocumentSetTemplate : SPOWebCmdlet { diff --git a/Commands/Enums/CustomActionScope.cs b/Commands/Enums/CustomActionScope.cs index d56691f4e..7bbb806da 100644 --- a/Commands/Enums/CustomActionScope.cs +++ b/Commands/Enums/CustomActionScope.cs @@ -1,8 +1,23 @@ namespace OfficeDevPnP.PowerShell.Commands.Enums { + /// + /// Scopes to which a CustomAction can be targeted + /// public enum CustomActionScope { + /// + /// Sites + /// Web, - Site + + /// + /// Site collections + /// + Site, + + /// + /// Sites collections and sites + /// + All } } diff --git a/Commands/Features/DisableFeature.cs b/Commands/Features/DisableFeature.cs index 01dcf3dc7..7618af2fb 100644 --- a/Commands/Features/DisableFeature.cs +++ b/Commands/Features/DisableFeature.cs @@ -9,9 +9,18 @@ namespace OfficeDevPnP.PowerShell.Commands.Features { [Cmdlet("Disable", "SPOFeature", SupportsShouldProcess = false)] [CmdletHelp("Disables a feature", Category = CmdletHelpCategory.Features)] - [CmdletExample(Code = "PS:> Disable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe", SortOrder = 1)] - [CmdletExample(Code = "PS:> Disable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Force", SortOrder = 2)] - [CmdletExample(Code = "PS:> Disable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Scope Web", SortOrder = 3)] + [CmdletExample( + Code = "PS:> Disable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe", + Remarks = @"This will enable the feature with the id ""99a00f6e-fb81-4dc7-8eac-e09c6f9132fe""", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Disable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Force", + Remarks = @"This will enable the feature with the id ""99a00f6e-fb81-4dc7-8eac-e09c6f9132fe"" with force.", + SortOrder = 2)] + [CmdletExample( + Code = "PS:> Disable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Scope Web", + Remarks = @"This will enable the feature with the id ""99a00f6e-fb81-4dc7-8eac-e09c6f9132fe"" with the web scope.", + SortOrder = 3)] public class DisableFeature : SPOWebCmdlet { [Parameter(Mandatory = true, Position = 0, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "The id of the feature to disable.")] diff --git a/Commands/Features/EnableFeature.cs b/Commands/Features/EnableFeature.cs index afabfd0eb..e5e7610d5 100644 --- a/Commands/Features/EnableFeature.cs +++ b/Commands/Features/EnableFeature.cs @@ -8,9 +8,18 @@ namespace OfficeDevPnP.PowerShell.Commands.Features { [Cmdlet("Enable", "SPOFeature")] [CmdletHelp("Enables a feature", Category = CmdletHelpCategory.Features)] - [CmdletExample(Code = "PS:> Enable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe", SortOrder = 1)] - [CmdletExample(Code = "PS:> Enable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Force", SortOrder = 2)] - [CmdletExample(Code = "PS:> Enable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Scope Web", SortOrder = 3)] + [CmdletExample( + Code = "PS:> Enable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe", + Remarks = @"This will enable the feature with the id ""99a00f6e-fb81-4dc7-8eac-e09c6f9132fe""", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Enable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Force", + Remarks = @"This will enable the feature with the id ""99a00f6e-fb81-4dc7-8eac-e09c6f9132fe"" with force.", + SortOrder = 2)] + [CmdletExample( + Code = "PS:> Enable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Scope Web", + Remarks = @"This will enable the feature with the id ""99a00f6e-fb81-4dc7-8eac-e09c6f9132fe"" with the web scope.", + SortOrder = 3)] public class EnableFeature : SPOWebCmdlet { [Parameter(Mandatory = true, Position=0, ValueFromPipeline=true, HelpMessage = "The id of the feature to enable.")] diff --git a/Commands/Lists/AddView.cs b/Commands/Lists/AddView.cs index 2dd55c99b..1ed81504b 100644 --- a/Commands/Lists/AddView.cs +++ b/Commands/Lists/AddView.cs @@ -10,7 +10,12 @@ namespace OfficeDevPnP.PowerShell.Commands Category = CmdletHelpCategory.Lists)] [CmdletExample( Code = @"Add-SPOView -List ""Demo List"" -Title ""Demo View"" -Fields ""Title"",""Address""", + Remarks = @"Adds a view named ""Demo view"" to the ""Demo List"" list.", SortOrder = 1)] + [CmdletExample( + Code = @"Add-SPOView -List ""Demo List"" -Title ""Demo View"" -Fields ""Title"",""Address"" -Paged", + Remarks = @"Adds a view named ""Demo view"" to the ""Demo List"" list and makes sure there's paging on this view.", + SortOrder = 2)] public class AddView : SPOWebCmdlet { [Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "The ID or Url of the list.")] @@ -34,15 +39,18 @@ public class AddView : SPOWebCmdlet [Parameter(Mandatory = false, HelpMessage = "If specified, a personal view will be created.")] public SwitchParameter Personal; - [Parameter(Mandatory = false, HelpMessage = "If specified the view will be set as the default view for the list.")] + [Parameter(Mandatory = false, HelpMessage = "If specified, the view will be set as the default view for the list.")] public SwitchParameter SetAsDefault; + + [Parameter(Mandatory = false, HelpMessage = "If specified, the view will have paging.")] + public SwitchParameter Paged; protected override void ExecuteCmdlet() { var list = List.GetList(SelectedWeb); if (list != null) { - var view = list.CreateView(Title, ViewType, Fields, RowLimit, SetAsDefault, Query, Personal); + var view = list.CreateView(Title, ViewType, Fields, RowLimit, SetAsDefault, Query, Personal, Paged); WriteObject(view); } diff --git a/Commands/Lists/SetListItem.cs b/Commands/Lists/SetListItem.cs new file mode 100644 index 000000000..a61a170ba --- /dev/null +++ b/Commands/Lists/SetListItem.cs @@ -0,0 +1,94 @@ +using System; +using System.Management.Automation; +using System.Text; +using Microsoft.SharePoint.Client; +using OfficeDevPnP.PowerShell.CmdletHelpAttributes; +using OfficeDevPnP.PowerShell.Commands.Base.PipeBinds; +using System.Linq; +using System.Xml.Linq; +using System.Collections; + +namespace OfficeDevPnP.PowerShell.Commands.Lists +{ + [Cmdlet(VerbsCommon.Set, "SPOListItem")] + [CmdletHelp("Updates a list item", + Category = CmdletHelpCategory.Lists)] + [CmdletExample( + Code = @"Set-SPOListItem -List ""Demo List"" -Identity 1 -Values @{""Title"" = ""Test Title""; ""Category""=""Test Category""}", + Remarks = @"Sets fields value in the list item with ID 1 in the ""Demo List"". It sets both the Title and Category fields with the specified values. Notice, use the internal names of fields.", + SortOrder = 1)] + [CmdletExample( + Code = @"Add-SPOListItem -List ""Demo List"" -Identity 1 -ContentType ""Company"" -Values @{""Title"" = ""Test Title""; ""Category""=""Test Category""}", + Remarks = @"Sets fields value in the list item with ID 1 in the ""Demo List"". It sets the content type of the item to ""Company"" and it sets both the Title and Category fields with the specified values. Notice, use the internal names of fields.", + SortOrder = 2)] + [CmdletExample( + Code = @"Add-SPOListItem -List ""Demo List"" -Identity $item -Values @{""Title"" = ""Test Title""; ""Category""=""Test Category""}", + Remarks = @"Sets fields value in the list item which has been retrieved by for instance Get-SPOListItem.. It sets the content type of the item to ""Company"" and it sets both the Title and Category fields with the specified values. Notice, use the internal names of fields.", + SortOrder = 3)] + public class SetListItem : SPOWebCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "The ID, Title or Url of the list.")] + public ListPipeBind List; + + [Parameter(Mandatory = true, HelpMessage = "The ID of the listitem, or actual ListItem object")] + public ListItemPipeBind Identity; + + [Parameter(Mandatory = false, HelpMessage = "Specify either the name, ID or an actual content type")] + public ContentTypePipeBind ContentType; + + [Parameter(Mandatory = false, HelpMessage = "Use the internal names of the fields when specifying field names")] + public Hashtable Values; + + protected override void ExecuteCmdlet() + { + List list = null; + if (List != null) + { + list = List.GetList(SelectedWeb); + } + if (list != null) + { + var item = Identity.GetListItem(list); + + if (ContentType != null) + { + ContentType ct = null; + if (ContentType.ContentType == null) + { + if (ContentType.Id != null) + { + ct = SelectedWeb.GetContentTypeById(ContentType.Id, true); + } + else if (ContentType.Name != null) + { + ct = SelectedWeb.GetContentTypeByName(ContentType.Name, true); + } + } + else + { + ct = ContentType.ContentType; + } + if (ct != null) + { + ct.EnsureProperty(w => w.StringId); + + item["ContentTypeId"] = ct.StringId; + item.Update(); + ClientContext.ExecuteQueryRetry(); + } + } + + foreach (var key in Values.Keys) + { + item[key as string] = Values[key]; + } + + + item.Update(); + ClientContext.Load(item); + ClientContext.ExecuteQueryRetry(); + WriteObject(item); + } + } + } +} diff --git a/Commands/Lists/SetListPermission.cs b/Commands/Lists/SetListPermission.cs index 23807877d..61b979299 100644 --- a/Commands/Lists/SetListPermission.cs +++ b/Commands/Lists/SetListPermission.cs @@ -11,6 +11,14 @@ namespace OfficeDevPnP.PowerShell.Commands.Lists [Cmdlet(VerbsCommon.Set, "SPOListPermission")] [CmdletHelp("Sets list permissions", Category = CmdletHelpCategory.Lists)] + [CmdletExample( + Code = "PS:> Set-SPOListPermission -Identity 'Documents' -User 'user@contoso.com' -AddRole 'Contribute'", + Remarks = "Adds the 'Contribute' permission to the user 'user@contoso.com' for the list 'Documents'", + SortOrder = 1)] + [CmdletExample( + Code = "PS:> Set-SPOListPermission -Identity 'Documents' -User 'user@contoso.com' -RemoveRole 'Contribute'", + Remarks = "Removes the 'Contribute' permission to the user 'user@contoso.com' for the list 'Documents'", + SortOrder = 2)] public class SetListPermission : SPOWebCmdlet { [Parameter(Mandatory = true, ParameterSetName = ParameterAttribute.AllParameterSets)] diff --git a/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V15.Commands.Format.ps1xml b/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V15.Commands.Format.ps1xml index b4a095232..e537c0085 100644 --- a/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V15.Commands.Format.ps1xml +++ b/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V15.Commands.Format.ps1xml @@ -179,7 +179,6 @@ - 30 left @@ -188,7 +187,6 @@ - 30 left @@ -292,11 +290,9 @@ - 30 left - 30 left @@ -403,7 +399,6 @@ - 40 left diff --git a/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V15.Commands.psd1 b/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V15.Commands.psd1 index ff45487ff..9bf32ecd7 100644 Binary files a/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V15.Commands.psd1 and b/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V15.Commands.psd1 differ diff --git a/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V16.Commands.Format.ps1xml b/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V16.Commands.Format.ps1xml index b4a095232..e537c0085 100644 --- a/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V16.Commands.Format.ps1xml +++ b/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V16.Commands.Format.ps1xml @@ -179,7 +179,6 @@ - 30 left @@ -188,7 +187,6 @@ - 30 left @@ -292,11 +290,9 @@ - 30 left - 30 left @@ -403,7 +399,6 @@ - 40 left diff --git a/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V16.Commands.psd1 b/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V16.Commands.psd1 index 5248ac34e..1e59f1a59 100644 Binary files a/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V16.Commands.psd1 and b/Commands/ModuleFiles/OfficeDevPnP.PowerShell.V16.Commands.psd1 differ diff --git a/Commands/OfficeDevPnP.PowerShell.Commands.csproj b/Commands/OfficeDevPnP.PowerShell.Commands.csproj index 0cdc71ca3..e48879bfd 100644 --- a/Commands/OfficeDevPnP.PowerShell.Commands.csproj +++ b/Commands/OfficeDevPnP.PowerShell.Commands.csproj @@ -79,51 +79,51 @@ False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.Office.Client.Policy.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.Office.Client.Policy.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.Office.Client.TranslationServices.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.Office.Client.TranslationServices.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.Online.SharePoint.Client.Tenant.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.Online.SharePoint.Client.Tenant.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.DocumentManagement.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.DocumentManagement.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.Publishing.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.Publishing.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.Runtime.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.Runtime.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.Search.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.Search.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.Search.Applications.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.Search.Applications.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.Taxonomy.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.Taxonomy.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.UserProfiles.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.UserProfiles.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.WorkflowServices.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.WorkflowServices.dll @@ -184,12 +184,12 @@ True - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.19.208020213\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.18.206251556\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll True - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.19.208020213\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.18.206251556\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll True @@ -242,14 +242,15 @@ + - + - + @@ -260,6 +261,7 @@ + @@ -306,6 +308,7 @@ + @@ -315,11 +318,15 @@ + + + + diff --git a/Commands/Principals/GetGroupPermissions.cs b/Commands/Principals/GetGroupPermissions.cs new file mode 100644 index 000000000..e4ef22f6f --- /dev/null +++ b/Commands/Principals/GetGroupPermissions.cs @@ -0,0 +1,32 @@ +using System.Management.Automation; +using Microsoft.SharePoint.Client; +using OfficeDevPnP.PowerShell.CmdletHelpAttributes; +using OfficeDevPnP.PowerShell.Commands.Base.PipeBinds; + +namespace OfficeDevPnP.PowerShell.Commands.Principals +{ + [Cmdlet(VerbsCommon.Get, "SPOGroupPermissions")] + [CmdletHelp("Returns the permissions for a specific SharePoint group", + Category = CmdletHelpCategory.Principals)] + [CmdletExample( + Code = @"PS:> Get-SPOGroupPermissions -Identity 'My Site Members'", + Remarks = "Returns the permissions for the SharePoint group with the name 'My Site Members'", + SortOrder = 0)] + public class GetGroupPermissions : SPOWebCmdlet + { + [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ParameterSetName = "ByName", HelpMessage = "Get the permissions of a specific group by name")] + [Alias("Name")] + public GroupPipeBind Identity = new GroupPipeBind(); + + protected override void ExecuteCmdlet() + { + var group = Identity.GetGroup(SelectedWeb); + var roleAssignment = SelectedWeb.RoleAssignments.GetByPrincipal(group); + var roleDefinitionBindings = roleAssignment.RoleDefinitionBindings; + ClientContext.Load(roleDefinitionBindings); + ClientContext.ExecuteQueryRetry(); + + WriteObject(roleDefinitionBindings, true); + } + } +} diff --git a/Commands/Principals/SetGroup.cs b/Commands/Principals/SetGroup.cs index 30425974d..bf5fe8a40 100644 --- a/Commands/Principals/SetGroup.cs +++ b/Commands/Principals/SetGroup.cs @@ -18,10 +18,10 @@ public class SetGroup : SPOWebCmdlet [Parameter(Mandatory = false)] public AssociatedGroupType SetAssociatedGroup = AssociatedGroupType.None; - [Parameter(Mandatory = false)] + [Parameter(Mandatory = false, HelpMessage = "Name of the permission set to add to this SharePoint group")] public string AddRole = string.Empty; - [Parameter(Mandatory = false)] + [Parameter(Mandatory = false, HelpMessage = "Name of the permission set to remove from this SharePoint group")] public string RemoveRole = string.Empty; [Parameter(Mandatory = false)] diff --git a/Commands/Principals/SetGroupPermissions.cs b/Commands/Principals/SetGroupPermissions.cs new file mode 100644 index 000000000..3f29dd2ed --- /dev/null +++ b/Commands/Principals/SetGroupPermissions.cs @@ -0,0 +1,75 @@ +using System.Linq; +using System.Management.Automation; +using Microsoft.SharePoint.Client; +using OfficeDevPnP.PowerShell.CmdletHelpAttributes; +using OfficeDevPnP.PowerShell.Commands.Base.PipeBinds; + +namespace OfficeDevPnP.PowerShell.Commands.Principals +{ + [Cmdlet(VerbsCommon.Set, "SPOGroupPermissions")] + [CmdletHelp("Adds and/or removes permissions of a specific SharePoint group", + Category = CmdletHelpCategory.Principals)] + [CmdletExample( + Code = @"PS:> Set-SPOGroupPermissions -Identity 'My Site Members' -AddRole Contribute", + Remarks = "Adds the 'Contribute' permission to the SharePoint group with the name 'My Site Members'", + SortOrder = 1)] + [CmdletExample( + Code = @"PS:> Set-SPOGroupPermissions -Identity 'My Site Members' -RemoveRole 'Full Control' -AddRole 'Read'", + Remarks = "Removes the 'Full Control' from and adds the 'Contribute' permissions to the SharePoint group with the name 'My Site Members'", + SortOrder = 2)] + [CmdletExample( + Code = @"PS:> Set-SPOGroupPermissions -Identity 'My Site Members' -AddRole @('Contribute', 'Design')", + Remarks = "Adds the 'Contribute' and 'Design' permissions to the SharePoint group with the name 'My Site Members'", + SortOrder = 3)] + [CmdletExample( + Code = @"PS:> Set-SPOGroupPermissions -Identity 'My Site Members' -RemoveRole @('Contribute', 'Design')", + Remarks = "Removes the 'Contribute' and 'Design' permissions from the SharePoint group with the name 'My Site Members'", + SortOrder = 4)] + public class SetGroupPermissions : SPOWebCmdlet + { + [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ParameterSetName = "ByName", HelpMessage = "Get the permissions of a specific group by name")] + [Alias("Name")] + public GroupPipeBind Identity = new GroupPipeBind(); + + [Parameter(Mandatory = false, HelpMessage = "Name of the permission set to add to this SharePoint group")] + public string[] AddRole = null; + + [Parameter(Mandatory = false, HelpMessage = "Name of the permission set to remove from this SharePoint group")] + public string[] RemoveRole = null; + + protected override void ExecuteCmdlet() + { + var group = Identity.GetGroup(SelectedWeb); + + if (AddRole != null) + { + foreach (var role in AddRole) + { + var roleDefinition = SelectedWeb.RoleDefinitions.GetByName(role); + var roleDefinitionBindings = new RoleDefinitionBindingCollection(ClientContext) {roleDefinition}; + var roleAssignments = SelectedWeb.RoleAssignments; + roleAssignments.Add(group, roleDefinitionBindings); + ClientContext.Load(roleAssignments); + ClientContext.ExecuteQueryRetry(); + } + } + if (RemoveRole != null) + { + foreach (var role in RemoveRole) + { + var roleAssignment = SelectedWeb.RoleAssignments.GetByPrincipal(group); + var roleDefinitionBindings = roleAssignment.RoleDefinitionBindings; + ClientContext.Load(roleDefinitionBindings); + ClientContext.ExecuteQueryRetry(); + foreach (var roleDefinition in roleDefinitionBindings.Where(roleDefinition => roleDefinition.Name == role)) + { + roleDefinitionBindings.Remove(roleDefinition); + roleAssignment.Update(); + ClientContext.ExecuteQueryRetry(); + break; + } + } + } + } + } +} diff --git a/Commands/Properties/AssemblyInfo.cs b/Commands/Properties/AssemblyInfo.cs index 5f9a80f2e..7fa9e37e1 100644 --- a/Commands/Properties/AssemblyInfo.cs +++ b/Commands/Properties/AssemblyInfo.cs @@ -39,5 +39,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.9.1215.0")] -[assembly: AssemblyFileVersion("1.9.1215.0")] +[assembly: AssemblyVersion("2.0.1601.0")] +[assembly: AssemblyFileVersion("2.0.1601.0")] diff --git a/Commands/Site/GetAuditing.cs b/Commands/Site/GetAuditing.cs new file mode 100644 index 000000000..b8abb715d --- /dev/null +++ b/Commands/Site/GetAuditing.cs @@ -0,0 +1,24 @@ +using System.Management.Automation; +using Microsoft.SharePoint.Client; +using OfficeDevPnP.PowerShell.CmdletHelpAttributes; + +namespace OfficeDevPnP.PowerShell.Commands +{ + [Cmdlet(VerbsCommon.Get, "SPOAuditing")] + [CmdletHelp("Get the Auditing setting of a site", + Category = CmdletHelpCategory.Sites)] + [CmdletExample( + Code = @"PS:> Get-SPOAuditing", + Remarks = "Gets the auditing settings of the current site", + SortOrder = 1)] + public class GetAuditing : SPOCmdlet + { + protected override void ExecuteCmdlet() + { + var audit = ClientContext.Site.Audit; + ClientContext.Load(audit); + ClientContext.ExecuteQueryRetry(); + WriteObject(audit); + } + } +} diff --git a/Commands/Site/SetAuditing.cs b/Commands/Site/SetAuditing.cs new file mode 100644 index 000000000..a577f6ea6 --- /dev/null +++ b/Commands/Site/SetAuditing.cs @@ -0,0 +1,145 @@ +using System.Management.Automation; +using Microsoft.SharePoint.Client; +using OfficeDevPnP.PowerShell.CmdletHelpAttributes; + +namespace OfficeDevPnP.PowerShell.Commands +{ + [Cmdlet(VerbsCommon.Set, "SPOAuditing")] + [CmdletHelp("Set Auditing setting for a site", + Category = CmdletHelpCategory.Sites)] + [CmdletExample( + Code = @"PS:> Set-SPOAuditing -EnableAll", + Remarks = "Enables all auditing settings for the current site", + SortOrder = 1)] + [CmdletExample( + Code = @"PS:> Set-SPOAuditing -DisableAll", + Remarks = @"Disables all auditing settings for the current site + This also disables the automatic trimming of the audit log", + SortOrder = 2)] + [CmdletExample( + Code = @"PS:> Set-SPOAuditing -RetentionTime 7", + Remarks = "Sets the audit log trimming to 7 days, this also enables the automatic trimming of the audit log", + SortOrder = 3)] + [CmdletExample( + Code = @"PS:> Set-SPOAuditing -TrimAuditLog", + Remarks = "Enables the automatic trimming of the audit log", + SortOrder = 4)] + [CmdletExample( + Code = @"PS:> Set-SPOAuditing -RetentionTime 7 -CheckOutCheckInItems -MoveCopyItems -SearchContent", + Remarks = @"Sets the audit log trimming to 7 days, this also enables the automatic trimming of the audit log. + Do auditing for: + - Checking out or checking in items + - Moving or copying items to another location in the site + - Searching site content", + SortOrder = 5)] + public class SetAuditing : SPOCmdlet + { + [Parameter(Mandatory = false, ParameterSetName ="EnableAll")] + public SwitchParameter EnableAll; + [Parameter(Mandatory = false, ParameterSetName = "DisableAll")] + public SwitchParameter DisableAll; + + [Parameter(Mandatory = false, ParameterSetName = "Other")] + [Parameter(ParameterSetName = "EnableAll")] + public int RetentionTime = -1; + [Parameter(Mandatory = false, ParameterSetName = "Other")] + [Parameter(ParameterSetName = "EnableAll")] + public SwitchParameter TrimAuditLog; + + //Editing items + //AuditMaskType.Update + [Parameter(Mandatory = false, ParameterSetName = "Other")] + public SwitchParameter EditItems; + + //Checking out or checking in items + //AuditMaskType.CheckOut and AuditMaskType.CheckIn + [Parameter(Mandatory = false, ParameterSetName = "Other")] + public SwitchParameter CheckOutCheckInItems; + + //Moving or copying items to another location in the site + //AuditMaskType.Copy and AuditMaskType.Move + [Parameter(Mandatory = false, ParameterSetName = "Other")] + public SwitchParameter MoveCopyItems; + + //Deleting or restoring items + //AuditMaskType.Undelete and AuditMaskType.ObjectDelete + [Parameter(Mandatory = false, ParameterSetName = "Other")] + public SwitchParameter DeleteRestoreItems; + + //Editing content types and columns + //AuditMaskType.SchemaChange and AuditMaskType.ProfileChange + [Parameter(Mandatory = false, ParameterSetName = "Other")] + public SwitchParameter EditContentTypesColumns; + + //Searching site content + //AuditMaskType.Search + [Parameter(Mandatory = false, ParameterSetName = "Other")] + public SwitchParameter SearchContent; + + //Editing users and permissions + //AuditMaskType.SecurityChange + [Parameter(Mandatory = false, ParameterSetName = "Other")] + public SwitchParameter EditUsersPermissions; + + protected override void ExecuteCmdlet() + { + var UpdateAudit = false; + var audit = ClientContext.Site.Audit; + var AuditFlags = audit.AuditFlags; + ClientContext.Load(audit); + ClientContext.ExecuteQueryRetry(); + + if (EnableAll) + { + AuditFlags = AuditMaskType.All; + UpdateAudit = true; + } + if(DisableAll) + { + AuditFlags = AuditMaskType.None; + UpdateAudit = true; + ClientContext.Site.TrimAuditLog = false; + } + if(RetentionTime != -1) + { + ClientContext.Site.AuditLogTrimmingRetention = RetentionTime; + ClientContext.Site.TrimAuditLog = true; + } + if(TrimAuditLog.IsPresent) + { + ClientContext.Site.TrimAuditLog = true; + } + + //set the events to audit + //AuditMaskType.Update + if (EditItems.IsPresent) { AuditFlags = AuditFlags | AuditMaskType.Update; UpdateAudit = true; } + + //AuditMaskType.CheckOut and AuditMaskType.CheckIn + if(CheckOutCheckInItems.IsPresent) { AuditFlags = AuditFlags | AuditMaskType.CheckOut | AuditMaskType.CheckIn; UpdateAudit = true; } + + //AuditMaskType.Copy and AuditMaskType.Move + if (MoveCopyItems.IsPresent) { AuditFlags = AuditFlags | AuditMaskType.Copy | AuditMaskType.Move; UpdateAudit = true; } + + //AuditMaskType.Undelete and AuditMaskType.ObjectDelete + if (DeleteRestoreItems.IsPresent) { AuditFlags = AuditFlags | AuditMaskType.Undelete | AuditMaskType.ObjectDelete; UpdateAudit = true; } + + //AuditMaskType.SchemaChange and AuditMaskType.ProfileChange + if (EditContentTypesColumns.IsPresent) { AuditFlags = AuditFlags | AuditMaskType.SchemaChange | AuditMaskType.ProfileChange; UpdateAudit = true; } + + //AuditMaskType.Search + if (SearchContent.IsPresent) { AuditFlags = AuditFlags | AuditMaskType.Search; UpdateAudit = true; } + + //AuditMaskType.SecurityChange + if (EditUsersPermissions.IsPresent) { AuditFlags = AuditFlags | AuditMaskType.SecurityChange; UpdateAudit = true; } + + if(UpdateAudit) + { + ClientContext.Site.Audit.AuditFlags = AuditFlags; + ClientContext.Site.Audit.Update(); + } + + //Commit the changes + ClientContext.ExecuteQueryRetry(); + } + } +} diff --git a/Commands/Taxonomy/ExportTermGroupToXml.cs b/Commands/Taxonomy/ExportTermGroupToXml.cs index e848b98f1..a85431123 100644 --- a/Commands/Taxonomy/ExportTermGroupToXml.cs +++ b/Commands/Taxonomy/ExportTermGroupToXml.cs @@ -29,7 +29,7 @@ namespace OfficeDevPnP.PowerShell.Commands Remarks = "Exports all term groups in the default site collection term store to the file 'output.xml' in the current folder", SortOrder = 2)] [CmdletExample( - Code = @"PS:> Export-SPOTermGroupToXml -Out c:\output.xml -TermGroup ""Test Group""", + Code = @"PS:> Export-SPOTermGroupToXml -Out c:\output.xml -Identity ""Test Group""", Remarks = "Exports the term group with the specified name to the file 'output.xml' located in the root folder of the C: drive.", SortOrder = 3)] public class ExportTermGroup : SPOCmdlet @@ -87,7 +87,7 @@ protected override void ExecuteCmdlet() var document = XDocument.Parse(fullxml); - XNamespace pnp = XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_05; + XNamespace pnp = XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_12; var termGroupsElement = document.Root.Descendants(pnp + "TermGroups").FirstOrDefault(); diff --git a/Commands/Taxonomy/ImportTermGroupFromXml.cs b/Commands/Taxonomy/ImportTermGroupFromXml.cs index 8aa6085fc..1c6c0d702 100644 --- a/Commands/Taxonomy/ImportTermGroupFromXml.cs +++ b/Commands/Taxonomy/ImportTermGroupFromXml.cs @@ -21,11 +21,11 @@ namespace OfficeDevPnP.PowerShell.Commands [CmdletHelp("Imports a taxonomy TermGroup from either the input or from an XML file.", Category = CmdletHelpCategory.Taxonomy)] [CmdletExample( - Code = @"PS:> Import-SPOTermGroupFromXml -Xml $xml", + Code = @"PS:> Import-SPOTermGroupFromXml -Xml $xml", Remarks = "Imports the XML based termgroup information located in the $xml variable", SortOrder = 1)] [CmdletExample( - Code = @"PS:> Import-SPOTermGroupFromXml -Path input.xml", + Code = @"PS:> Import-SPOTermGroupFromXml -Path input.xml", Remarks = "Imports the XML file specified by the path.", SortOrder = 2)] public class ImportTermGroupFromXml : SPOCmdlet @@ -44,7 +44,7 @@ protected override void ExecuteCmdlet() template.Features = null; template.CustomActions = null; template.ComposedLook = null; - + template.Id = "TAXONOMYPROVISIONING"; var outputStream = XMLPnPSchemaFormatter.LatestFormatter.ToFormattedTemplate(template); @@ -69,7 +69,7 @@ protected override void ExecuteCmdlet() termGroupsElement = XElement.Parse(File.ReadAllText(Path)); } - XNamespace pnp = XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_05; + XNamespace pnp = XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_12; var templateElement = document.Root.Descendants(pnp + "ProvisioningTemplate").FirstOrDefault(); if (templateElement != null) diff --git a/Commands/Web/RemoveWeb.cs b/Commands/Web/RemoveWeb.cs index df40c298c..9327e0811 100644 --- a/Commands/Web/RemoveWeb.cs +++ b/Commands/Web/RemoveWeb.cs @@ -1,6 +1,8 @@ using System.Management.Automation; using Microsoft.SharePoint.Client; using OfficeDevPnP.PowerShell.CmdletHelpAttributes; +using OfficeDevPnP.PowerShell.Commands.Base.PipeBinds; +using System; namespace OfficeDevPnP.PowerShell.Commands { @@ -12,22 +14,73 @@ namespace OfficeDevPnP.PowerShell.Commands Remarks = "Remove a web", SortOrder = 1)] + [CmdletExample( + Code = @"PS:> Remove-SPOWeb -Identity 5fecaf67-6b9e-4691-a0ff-518fc9839aa0", + Remarks = "Remove a web specified by its ID", + SortOrder = 2)] + + [CmdletExample( + Code = @"PS:> Get-SPOSubWebs | Remove-SPOWeb -Force", + Remarks = "Remove all subwebs and do not ask for confirmation", + SortOrder = 2)] + + public class RemoveWeb : SPOWebCmdlet { - [Parameter(Mandatory = true, HelpMessage = "The Url of the web")] + [Parameter(Mandatory = true, HelpMessage = "The site relative url of the web, e.g. 'Subweb1'", ParameterSetName = "ByUrl")] public string Url; - [Parameter(Mandatory = false)] + [Parameter(Mandatory = true, HelpMessage = "Identity/Id/Web object to delete", ParameterSetName = "ByIdentity", ValueFromPipeline = true)] + public WebPipeBind Identity; + + [Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation to delete the subweb", ParameterSetName = ParameterAttribute.AllParameterSets)] public SwitchParameter Force; protected override void ExecuteCmdlet() { - var web = SelectedWeb.GetWeb(Url); - if (Force || ShouldContinue(string.Format(Properties.Resources.RemoveWeb0, web.Title), Properties.Resources.Confirm)) + if (ParameterSetName == "ByIdentity") { - SelectedWeb.DeleteWeb(Url); - ClientContext.ExecuteQueryRetry(); + Web web = null; + if (Identity.Id != Guid.Empty) + { + web = ClientContext.Web.GetWebById(Identity.Id); + web.EnsureProperty(w => w.Title); + if (Force || ShouldContinue(string.Format(Properties.Resources.RemoveWeb0, web.Title), Properties.Resources.Confirm)) + { + web.DeleteObject(); + web.Context.ExecuteQueryRetry(); + } + } + else if (Identity.Web != null) + { + Identity.Web.EnsureProperty(w => w.Title); + if (Force || ShouldContinue(string.Format(Properties.Resources.RemoveWeb0, Identity.Web.Title), Properties.Resources.Confirm)) + { + Identity.Web.DeleteObject(); + Identity.Web.Context.ExecuteQueryRetry(); + } + } + else if (Identity.Url != null) + { + web = ClientContext.Web.GetWebByUrl(Identity.Url); + web.EnsureProperty(w => w.Title); + if (Force || ShouldContinue(string.Format(Properties.Resources.RemoveWeb0, Identity.Web.Title), Properties.Resources.Confirm)) + { + web.DeleteObject(); + web.Context.ExecuteQueryRetry(); + } + } + + } + else { + var web = SelectedWeb.GetWeb(Url); + web.EnsureProperty(w => w.Title); + if (Force || ShouldContinue(string.Format(Properties.Resources.RemoveWeb0, web.Title), Properties.Resources.Confirm)) + { + SelectedWeb.DeleteWeb(Url); + ClientContext.ExecuteQueryRetry(); + } } } } -} +} \ No newline at end of file diff --git a/Commands/packages.config b/Commands/packages.config index ee8761d5a..f4dd4287e 100644 --- a/Commands/packages.config +++ b/Commands/packages.config @@ -3,6 +3,6 @@ - + \ No newline at end of file diff --git a/Documentation/AddSPOCustomAction.md b/Documentation/AddSPOCustomAction.md index f2ea85016..620c5a479 100644 --- a/Documentation/AddSPOCustomAction.md +++ b/Documentation/AddSPOCustomAction.md @@ -18,8 +18,8 @@ Parameter|Type|Required|Description |RegistrationId|String|False|| |RegistrationType|UserCustomActionRegistrationType|False|| |Rights|PermissionKind[]|False|| -|Scope|CustomActionScope|False|| -|Sequence|Int32|False|| +|Scope|CustomActionScope|False|The scope of the CustomAction to add to. Either Web or Site, defaults to Web. All is not valid for this command.| +|Sequence|Int32|False|Sequence of this CustomAction being injected. Use when you have a specific sequence with which to have multple CustomActions being added to the page.| |Title|String|True|| |Url|String|False|| |Web|WebPipeBind|False|The web to apply the command to. Omit this parameter to use the current web.| diff --git a/Documentation/AddSPOJavaScriptBlock.md b/Documentation/AddSPOJavaScriptBlock.md index c8d11ebf8..ab7be151d 100644 --- a/Documentation/AddSPOJavaScriptBlock.md +++ b/Documentation/AddSPOJavaScriptBlock.md @@ -13,7 +13,7 @@ Specify a scope as 'Site' to add the custom action to all sites in a site collec Parameter|Type|Required|Description ---------|----|--------|----------- |Name|String|True|The name of the script block. Can be used to identiy the script with other cmdlets or coded solutions| -|Scope|CustomActionScope|False|The scope of the script to add to. Either Web or Site, defaults to Web.| +|Scope|CustomActionScope|False|The scope of the script to add to. Either Web or Site, defaults to Web. All is not valid for this command.| |Script|String|True|The javascript block to add| |Sequence|Int32|False|| |Web|WebPipeBind|False|The web to apply the command to. Omit this parameter to use the current web.| diff --git a/Documentation/AddSPOJavaScriptLink.md b/Documentation/AddSPOJavaScriptLink.md index c629ec157..5cd8429d1 100644 --- a/Documentation/AddSPOJavaScriptLink.md +++ b/Documentation/AddSPOJavaScriptLink.md @@ -2,15 +2,28 @@ Adds a link to a JavaScript file to a web or sitecollection ##Syntax ```powershell -Add-SPOJavaScriptLink -Key -Url [-Sequence ] [-Scope ] [-Web ] +Add-SPOJavaScriptLink -Name -Url [-Sequence ] [-Scope ] [-Web ] ``` ##Parameters Parameter|Type|Required|Description ---------|----|--------|----------- -|Key|String|True|| -|Scope|CustomActionScope|False|| -|Sequence|Int32|False|| -|Url|String[]|True|| +|Name|String|True|Name under which to register the JavaScriptLink| +|Scope|CustomActionScope|False|Defines if this JavaScript file will be injected to every page within the current site collection or web. All is not allowed in for this command. Default is web.| +|Sequence|Int32|False|Sequence of this JavaScript being injected. Use when you have a specific sequence with which to have JavaScript files being added to the page. I.e. jQuery library first and then jQueryUI.| +|Url|String[]|True|URL to the JavaScript file to inject| |Web|WebPipeBind|False|The web to apply the command to. Omit this parameter to use the current web.| +##Examples + +###Example 1 +```powershell +PS:> Add-SPOJavaScriptLink -Name jQuery -Url https://code.jquery.com/jquery.min.js -Sequence 9999 -Scope Site +``` +Injects a reference to the latest v1 series jQuery library to all pages within the current site collection under the name jQuery and at order 9999 + +###Example 2 +```powershell +PS:> Add-SPOJavaScriptLink -Name jQuery -Url https://code.jquery.com/jquery.min.js +``` +Injects a reference to the latest v1 series jQuery library to all pages within the current web under the name jQuery diff --git a/Documentation/AddSPOView.md b/Documentation/AddSPOView.md index 3f8763897..ce39c7cfd 100644 --- a/Documentation/AddSPOView.md +++ b/Documentation/AddSPOView.md @@ -2,7 +2,7 @@ Adds a view to a list ##Syntax ```powershell -Add-SPOView -Title [-Query ] -Fields [-ViewType ] [-RowLimit ] [-Personal []] [-SetAsDefault []] [-Web ] -List +Add-SPOView -Title [-Query ] -Fields [-ViewType ] [-RowLimit ] [-Personal []] [-SetAsDefault []] [-Paged []] [-Web ] -List ``` @@ -11,10 +11,11 @@ Parameter|Type|Required|Description ---------|----|--------|----------- |Fields|String[]|True|A list of fields to add.| |List|ListPipeBind|True|The ID or Url of the list.| +|Paged|SwitchParameter|False|If specified, the view will have paging.| |Personal|SwitchParameter|False|If specified, a personal view will be created.| |Query|String|False|A valid CAML Query.| |RowLimit|UInt32|False|The row limit for the view. Defaults to 30.| -|SetAsDefault|SwitchParameter|False|If specified the view will be set as the default view for the list.| +|SetAsDefault|SwitchParameter|False|If specified, the view will be set as the default view for the list.| |Title|String|True|The title of the view.| |ViewType|ViewType|False|The type of view to add.| |Web|WebPipeBind|False|The web to apply the command to. Omit this parameter to use the current web.| @@ -24,4 +25,10 @@ Parameter|Type|Required|Description ```powershell Add-SPOView -List "Demo List" -Title "Demo View" -Fields "Title","Address" ``` +Adds a view named "Demo view" to the "Demo List" list. +###Example 2 +```powershell +Add-SPOView -List "Demo List" -Title "Demo View" -Fields "Title","Address" -Paged +``` +Adds a view named "Demo view" to the "Demo List" list and makes sure there's paging on this view. diff --git a/Documentation/ApplySPOProvisioningTemplate.md b/Documentation/ApplySPOProvisioningTemplate.md index a34d82758..bf8e49210 100644 --- a/Documentation/ApplySPOProvisioningTemplate.md +++ b/Documentation/ApplySPOProvisioningTemplate.md @@ -2,13 +2,14 @@ Applies a provisioning template to a web ##Syntax ```powershell -Apply-SPOProvisioningTemplate [-ResourceFolder ] [-OverwriteSystemPropertyBagValues []] [-Parameters ] [-Web ] -Path +Apply-SPOProvisioningTemplate [-ResourceFolder ] [-OverwriteSystemPropertyBagValues []] [-Parameters ] [-Handlers ] [-Web ] -Path ``` ##Parameters Parameter|Type|Required|Description ---------|----|--------|----------- +|Handlers|Handlers|False|Allows you to only process a specific part of the template. Notice that this might fail, as some of the handlers require other artifacts in place if they are not part of what your applying.| |OverwriteSystemPropertyBagValues|SwitchParameter|False|Specify this parameter if you want to overwrite and/or create properties that are known to be system entries (starting with vti_, dlc_, etc.)| |Parameters|Hashtable|False|Allows you to specify parameters that can be referred to in the template by means of the {parameter:} token. See examples on how to use this parameter.| |Path|String|True|Path to the xml file containing the provisioning template.| @@ -18,28 +19,28 @@ Parameter|Type|Required|Description ###Example 1 ```powershell - - PS:> Apply-SPOProvisioningTemplate -Path template.xml - +PS:> Apply-SPOProvisioningTemplate -Path template.xml ``` Applies a provisioning template in XML format to the current web. ###Example 2 ```powershell - - PS:> Apply-SPOProvisioningTemplate -Path template.xml -ResourceFolder c:\provisioning\resources - +PS:> Apply-SPOProvisioningTemplate -Path template.xml -ResourceFolder c:\provisioning\resources ``` Applies a provisioning template in XML format to the current web. Any resources like files that are referenced in the template will be retrieved from the folder as specified with the ResourceFolder parameter. ###Example 3 ```powershell - - PS:> Apply-SPOProvisioningTemplate -Path template.xml -Parameters @{"ListTitle"="Projects";"parameter2"="a second value"} - +PS:> Apply-SPOProvisioningTemplate -Path template.xml -Parameters @{"ListTitle"="Projects";"parameter2"="a second value"} ``` Applies a provisioning template in XML format to the current web. It will populate the parameter in the template the values as specified and in the template you can refer to those values with the {parameter:} token. For instance with the example above, specifying {parameter:ListTitle} in your template will translate to 'Projects' when applying the template. These tokens can be used in most string values in a template. + +###Example 4 +```powershell +PS:> Apply-SPOProvisioningTemplate -Path template.xml -Handlers Lists, SiteSecurity +``` +Applies a provisioning template in XML format to the current web. It will only apply the lists and site security part of the template. diff --git a/Documentation/ConnectSPOnline.md b/Documentation/ConnectSPOnline.md index 5fa41acf6..80b22e306 100644 --- a/Documentation/ConnectSPOnline.md +++ b/Documentation/ConnectSPOnline.md @@ -21,6 +21,11 @@ Connect-SPOnline [-Realm ] -AppId -AppSecret [-Minimal ``` +```powershell +Connect-SPOnline -UseWebLogin [] [-MinimalHealthScore ] [-RetryCount ] [-RetryWait ] [-RequestTimeout ] [-SkipTenantAdminCheck []] -Url +``` + + ##Detailed Description If no credentials have been specified, and the CurrentCredentials parameter has not been specified, you will be prompted for credentials. @@ -45,6 +50,7 @@ Parameter|Type|Required|Description |Tenant|String|True|The Azure AD Tenant name,e.g. mycompany.onmicrosoft.com| |Url|String|True|The Url of the site collection to connect to.| |UseAdfs|SwitchParameter|False|If you want to connect to your on-premises SharePoint farm using ADFS| +|UseWebLogin|SwitchParameter|True|If you want to connect to SharePoint with browser based login| ##Examples ###Example 1 diff --git a/Documentation/DisableSPOFeature.md b/Documentation/DisableSPOFeature.md index 28280d82b..fa6df893d 100644 --- a/Documentation/DisableSPOFeature.md +++ b/Documentation/DisableSPOFeature.md @@ -19,16 +19,16 @@ Parameter|Type|Required|Description ```powershell PS:> Disable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe ``` - +This will enable the feature with the id "99a00f6e-fb81-4dc7-8eac-e09c6f9132fe" ###Example 2 ```powershell PS:> Disable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Force ``` - +This will enable the feature with the id "99a00f6e-fb81-4dc7-8eac-e09c6f9132fe" with force. ###Example 3 ```powershell PS:> Disable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Scope Web ``` - +This will enable the feature with the id "99a00f6e-fb81-4dc7-8eac-e09c6f9132fe" with the web scope. diff --git a/Documentation/EnableSPOFeature.md b/Documentation/EnableSPOFeature.md index 8b7eb681b..30a55f6d1 100644 --- a/Documentation/EnableSPOFeature.md +++ b/Documentation/EnableSPOFeature.md @@ -20,16 +20,16 @@ Parameter|Type|Required|Description ```powershell PS:> Enable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe ``` - +This will enable the feature with the id "99a00f6e-fb81-4dc7-8eac-e09c6f9132fe" ###Example 2 ```powershell PS:> Enable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Force ``` - +This will enable the feature with the id "99a00f6e-fb81-4dc7-8eac-e09c6f9132fe" with force. ###Example 3 ```powershell PS:> Enable-SPOFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Scope Web ``` - +This will enable the feature with the id "99a00f6e-fb81-4dc7-8eac-e09c6f9132fe" with the web scope. diff --git a/Documentation/ExportSPOTermGroupToXml.md b/Documentation/ExportSPOTermGroupToXml.md index ed5e630bf..856ddb921 100644 --- a/Documentation/ExportSPOTermGroupToXml.md +++ b/Documentation/ExportSPOTermGroupToXml.md @@ -30,6 +30,6 @@ Exports all term groups in the default site collection term store to the file 'o ###Example 3 ```powershell -PS:> Export-SPOTermGroupToXml -Out c:\output.xml -TermGroup "Test Group" +PS:> Export-SPOTermGroupToXml -Out c:\output.xml -Identity "Test Group" ``` Exports the term group with the specified name to the file 'output.xml' located in the root folder of the C: drive. diff --git a/Documentation/GetSPOAuditing.md b/Documentation/GetSPOAuditing.md new file mode 100644 index 000000000..87e9acad4 --- /dev/null +++ b/Documentation/GetSPOAuditing.md @@ -0,0 +1,13 @@ +#Get-SPOAuditing +Get the Auditing setting of a site +##Syntax +##Parameters +Parameter|Type|Required|Description +---------|----|--------|----------- +##Examples + +###Example 1 +```powershell +PS:> Get-SPOAuditing +``` +Gets the auditing settings of the current site diff --git a/Documentation/GetSPOCustomAction.md b/Documentation/GetSPOCustomAction.md index a316fa7aa..0dfa97006 100644 --- a/Documentation/GetSPOCustomAction.md +++ b/Documentation/GetSPOCustomAction.md @@ -9,6 +9,6 @@ Get-SPOCustomAction [-Identity ] [-Scope ] [-We ##Parameters Parameter|Type|Required|Description ---------|----|--------|----------- -|Identity|GuidPipeBind|False|| -|Scope|CustomActionScope|False|| +|Identity|GuidPipeBind|False|Identity of the CustomAction to return. Omit to return all CustomActions.| +|Scope|CustomActionScope|False|Scope of the CustomAction, either Web, Site or All to return both| |Web|WebPipeBind|False|The web to apply the command to. Omit this parameter to use the current web.| diff --git a/Documentation/GetSPODocumentSetTemplate.md b/Documentation/GetSPODocumentSetTemplate.md index 69e27eef2..80b55ab63 100644 --- a/Documentation/GetSPODocumentSetTemplate.md +++ b/Documentation/GetSPODocumentSetTemplate.md @@ -17,10 +17,10 @@ Parameter|Type|Required|Description ```powershell PS:> Get-SPODocumentSetTemplate -Identity "Test Document Set" ``` - +This will get the document set template with the name "Test Document Set" ###Example 2 ```powershell PS:> Get-SPODocumentSetTemplate -Identity "0x0120D520005DB65D094035A241BAC9AF083F825F3B" ``` - +This will get the document set template with the id "0x0120D520005DB65D094035A241BAC9AF083F825F3B" diff --git a/Documentation/GetSPOGroupPermissions.md b/Documentation/GetSPOGroupPermissions.md new file mode 100644 index 000000000..f9246e51d --- /dev/null +++ b/Documentation/GetSPOGroupPermissions.md @@ -0,0 +1,20 @@ +#Get-SPOGroupPermissions +Returns the permissions for a specific SharePoint group +##Syntax +```powershell +Get-SPOGroupPermissions [-Web ] -Identity +``` + + +##Parameters +Parameter|Type|Required|Description +---------|----|--------|----------- +|Identity|GroupPipeBind|True|Get the permissions of a specific group by name| +|Web|WebPipeBind|False|The web to apply the command to. Omit this parameter to use the current web.| +##Examples + +###Example 1 +```powershell +PS:> Get-SPOGroupPermissions -Identity 'My Site Members' +``` +Returns the permissions for the SharePoint group with the name 'My Site Members' diff --git a/Documentation/GetSPOJavaScriptLink.md b/Documentation/GetSPOJavaScriptLink.md index 4fd0bdd79..7eb915383 100644 --- a/Documentation/GetSPOJavaScriptLink.md +++ b/Documentation/GetSPOJavaScriptLink.md @@ -10,5 +10,30 @@ Get-SPOJavaScriptLink [-Scope ] [-Web ] [-Name < Parameter|Type|Required|Description ---------|----|--------|----------- |Name|String|False|Name of the Javascript link. Omit this parameter to retrieve all script links| -|Scope|CustomActionScope|False|Scope of the action, either Web (default) or Site| +|Scope|CustomActionScope|False|Scope of the action, either Web, Site or All to return both| |Web|WebPipeBind|False|The web to apply the command to. Omit this parameter to use the current web.| +##Examples + +###Example 1 +```powershell +PS:> Get-SPOJavaScriptLink +``` +Returns all web and site scoped JavaScriptLinks + +###Example 2 +```powershell +PS:> Get-SPOJavaScriptLink -Scope Web +``` +Returns all site scoped JavaScriptLinks + +###Example 3 +```powershell +PS:> Get-SPOJavaScriptLink -Scope Site +``` +Returns all web scoped JavaScriptLinks + +###Example 4 +```powershell +PS:> Get-SPOJavaScriptLink -Name Test +``` +Returns the JavaScriptLink named Test diff --git a/Documentation/GetSPOProvisioningTemplate.md b/Documentation/GetSPOProvisioningTemplate.md index c89a178ce..de09a8e3e 100644 --- a/Documentation/GetSPOProvisioningTemplate.md +++ b/Documentation/GetSPOProvisioningTemplate.md @@ -2,7 +2,7 @@ Generates a provisioning template from a web ##Syntax ```powershell -Get-SPOProvisioningTemplate [-IncludeAllTermGroups []] [-IncludeSiteCollectionTermGroup []] [-IncludeSiteGroups []] [-PersistComposedLookFiles []] [-Force []] [-Encoding ] [-Web ] [-Out ] [-Schema ] +Get-SPOProvisioningTemplate [-IncludeAllTermGroups []] [-IncludeSiteCollectionTermGroup []] [-IncludeSiteGroups []] [-PersistBrandingFiles []] [-Force []] [-Encoding ] [-Handlers ] [-Web ] [-Out ] [-Schema ] ``` @@ -11,51 +11,48 @@ Parameter|Type|Required|Description ---------|----|--------|----------- |Encoding|Encoding|False|| |Force|SwitchParameter|False|Overwrites the output file if it exists.| +|Handlers|Handlers|False|Allows you to only process a specific type of artifact in the site. Notice that this might result in a non-working template, as some of the handlers require other artifacts in place if they are not part of what your extracting.| |IncludeAllTermGroups|SwitchParameter|False|If specified, all term groups will be included. Overrides IncludeSiteCollectionTermGroup.| |IncludeSiteCollectionTermGroup|SwitchParameter|False|If specified, all the site collection term groups will be included. Overridden by IncludeAllTermGroups.| |IncludeSiteGroups|SwitchParameter|False|If specified all site groups will be included.| |Out|String|False|Filename to write to, optionally including full path| -|PersistComposedLookFiles|SwitchParameter|False|If specified the files making up the composed look (background image, font file and color file) will be saved.| +|PersistBrandingFiles|SwitchParameter|False|If specified the files used for masterpages, sitelogo, alternate CSS and the files that make up the composed look will be saved.| |Schema|XMLPnPSchemaVersion|False|The schema of the output to use, defaults to the latest schema| |Web|WebPipeBind|False|The web to apply the command to. Omit this parameter to use the current web.| ##Examples ###Example 1 ```powershell - - PS:> Get-SPOProvisioningTemplate -Out template.xml - +PS:> Get-SPOProvisioningTemplate -Out template.xml ``` Extracts a provisioning template in XML format from the current web. ###Example 2 ```powershell - - PS:> Get-SPOProvisioningTemplate -Out template.xml -Schema V201503 - +PS:> Get-SPOProvisioningTemplate -Out template.xml -Schema V201503 ``` Extracts a provisioning template in XML format from the current web and saves it in the V201503 version of the schema. ###Example 3 ```powershell - - PS:> Get-SPOProvisioningTemplate -Out template.xml -IncludeAllTermGroups - +PS:> Get-SPOProvisioningTemplate -Out template.xml -IncludeAllTermGroups ``` Extracts a provisioning template in XML format from the current web and includes all term groups, term sets and terms from the Managed Metadata Service Taxonomy. ###Example 4 ```powershell - - PS:> Get-SPOProvisioningTemplate -Out template.xml -IncludeSiteCollectionTermGroup - +PS:> Get-SPOProvisioningTemplate -Out template.xml -IncludeSiteCollectionTermGroup ``` Extracts a provisioning template in XML format from the current web and includes the term group currently (if set) assigned to the site collection. ###Example 5 ```powershell - - PS:> Get-SPOProvisioningTemplate -Out template.xml -PersistComposedLookFiles - +PS:> Get-SPOProvisioningTemplate -Out template.xml -PersistComposedLookFiles ``` Extracts a provisioning template in XML format from the current web and saves the files that make up the composed look to the same folder as where the template is saved. + +###Example 6 +```powershell +PS:> Get-SPOProvisioningTemplate -Out template.xml -Handlers Lists, SiteSecurity +``` +Extracts a provisioning template in XML format from the current web, but only processes lists and site security when generating the template. diff --git a/Documentation/NewSPOProvisioningTemplateFromFolder.md b/Documentation/NewSPOProvisioningTemplateFromFolder.md index 5f287c64a..b787c2712 100644 --- a/Documentation/NewSPOProvisioningTemplateFromFolder.md +++ b/Documentation/NewSPOProvisioningTemplateFromFolder.md @@ -2,13 +2,14 @@ Generates a provisioning template from a given folder, including only files that are present in that folder ##Syntax ```powershell -New-SPOProvisioningTemplateFromFolder [-Match ] [-ContentType ] [-Properties ] [-Force []] [-Encoding ] [-Web ] [-Out ] [-Folder ] [-TargetFolder ] [-Schema ] +New-SPOProvisioningTemplateFromFolder [-Match ] [-ContentType ] [-Properties ] [-AsIncludeFile []] [-Force []] [-Encoding ] [-Web ] [-Out ] [-Folder ] [-TargetFolder ] [-Schema ] ``` ##Parameters Parameter|Type|Required|Description ---------|----|--------|----------- +|AsIncludeFile|SwitchParameter|False|If specified, the output will only contain the element. This allows the output to be included in another template.| |ContentType|ContentTypePipeBind|False|An optional content type to use.| |Encoding|Encoding|False|| |Folder|String|False|Folder to process. If not specified the current folder will be used.| diff --git a/Documentation/RemoveSPOCustomAction.md b/Documentation/RemoveSPOCustomAction.md index d0d3e6331..a004a6b4f 100644 --- a/Documentation/RemoveSPOCustomAction.md +++ b/Documentation/RemoveSPOCustomAction.md @@ -9,7 +9,7 @@ Remove-SPOCustomAction [-Scope ] [-Force []] ##Parameters Parameter|Type|Required|Description ---------|----|--------|----------- -|Force|SwitchParameter|False|| -|Identity|GuidPipeBind|True|| -|Scope|CustomActionScope|False|| +|Force|SwitchParameter|False|Use the -Force flag to bypass the confirmation question| +|Identity|GuidPipeBind|True|The identifier of the CustomAction that needs to be removed| +|Scope|CustomActionScope|False|Define if the CustomAction is to be found at the web or site collection scope. Specify All to allow deletion from either web or site collection.| |Web|WebPipeBind|False|The web to apply the command to. Omit this parameter to use the current web.| diff --git a/Documentation/RemoveSPOJavaScriptLink.md b/Documentation/RemoveSPOJavaScriptLink.md index 9fbed6ae1..eecf0803d 100644 --- a/Documentation/RemoveSPOJavaScriptLink.md +++ b/Documentation/RemoveSPOJavaScriptLink.md @@ -9,7 +9,26 @@ Remove-SPOJavaScriptLink [-Force []] [-Scope Remove-SPOJavaScriptLink -Name jQuery +``` +Removes the injected JavaScript file with the name jQuery from the current web after confirmation + +###Example 2 +```powershell +PS:> Remove-SPOJavaScriptLink -Name jQuery -Scope Site +``` +Removes the injected JavaScript file with the name jQuery from the current site collection after confirmation + +###Example 3 +```powershell +PS:> Remove-SPOJavaScriptLink -Name jQuery -Scope Site -Force +``` +Removes the injected JavaScript file with the name jQuery from the current site collection and will not ask for confirmation diff --git a/Documentation/RemoveSPOWeb.md b/Documentation/RemoveSPOWeb.md index 70cd754e4..f1c7267eb 100644 --- a/Documentation/RemoveSPOWeb.md +++ b/Documentation/RemoveSPOWeb.md @@ -1,6 +1,11 @@ #Remove-SPOWeb Removes a subweb in the current web ##Syntax +```powershell +Remove-SPOWeb -Identity [-Force []] [-Web ] +``` + + ```powershell Remove-SPOWeb -Url [-Force []] [-Web ] ``` @@ -9,8 +14,9 @@ Remove-SPOWeb -Url [-Force []] [-Web ] ##Parameters Parameter|Type|Required|Description ---------|----|--------|----------- -|Force|SwitchParameter|False|| -|Url|String|True|The Url of the web| +|Force|SwitchParameter|False|Do not ask for confirmation to delete the subweb| +|Identity|WebPipeBind|True|Identity/Id/Web object to delete| +|Url|String|True|The site relative url of the web, e.g. 'Subweb1'| |Web|WebPipeBind|False|The web to apply the command to. Omit this parameter to use the current web.| ##Examples @@ -19,3 +25,15 @@ Parameter|Type|Required|Description PS:> Remove-SPOWeb -Url projectA ``` Remove a web + +###Example 2 +```powershell +PS:> Remove-SPOWeb -Identity 5fecaf67-6b9e-4691-a0ff-518fc9839aa0 +``` +Remove a web specified by its ID + +###Example 3 +```powershell +PS:> Get-SPOSubWebs | Remove-SPOWeb -Force +``` +Remove all subwebs and do not ask for confirmation diff --git a/Documentation/SetSPOAuditing.md b/Documentation/SetSPOAuditing.md new file mode 100644 index 000000000..e170da60d --- /dev/null +++ b/Documentation/SetSPOAuditing.md @@ -0,0 +1,68 @@ +#Set-SPOAuditing +Set Auditing setting for a site +##Syntax +```powershell +Set-SPOAuditing [-DisableAll []] +``` + + +```powershell +Set-SPOAuditing [-EnableAll []] [-RetentionTime ] [-TrimAuditLog []] +``` + + +```powershell +Set-SPOAuditing [-RetentionTime ] [-TrimAuditLog []] [-EditItems []] [-CheckOutCheckInItems []] [-MoveCopyItems []] [-DeleteRestoreItems []] [-EditContentTypesColumns []] [-SearchContent []] [-EditUsersPermissions []] +``` + + +##Parameters +Parameter|Type|Required|Description +---------|----|--------|----------- +|CheckOutCheckInItems|SwitchParameter|False|| +|DeleteRestoreItems|SwitchParameter|False|| +|DisableAll|SwitchParameter|False|| +|EditContentTypesColumns|SwitchParameter|False|| +|EditItems|SwitchParameter|False|| +|EditUsersPermissions|SwitchParameter|False|| +|EnableAll|SwitchParameter|False|| +|MoveCopyItems|SwitchParameter|False|| +|RetentionTime|Int32|False|| +|SearchContent|SwitchParameter|False|| +|TrimAuditLog|SwitchParameter|False|| +##Examples + +###Example 1 +```powershell +PS:> Set-SPOAuditing -EnableAll +``` +Enables all auditing settings for the current site + +###Example 2 +```powershell +PS:> Set-SPOAuditing -DisableAll +``` +Disables all auditing settings for the current site + This also disables the automatic trimming of the audit log + +###Example 3 +```powershell +PS:> Set-SPOAuditing -RetentionTime 7 +``` +Sets the audit log trimming to 7 days, this also enables the automatic trimming of the audit log + +###Example 4 +```powershell +PS:> Set-SPOAuditing -TrimAuditLog +``` +Enables the automatic trimming of the audit log + +###Example 5 +```powershell +PS:> Set-SPOAuditing -RetentionTime 7 -CheckOutCheckInItems -MoveCopyItems -SearchContent +``` +Sets the audit log trimming to 7 days, this also enables the automatic trimming of the audit log. + Do auditing for: + - Checking out or checking in items + - Moving or copying items to another location in the site + - Searching site content diff --git a/Documentation/SetSPOContext.md b/Documentation/SetSPOContext.md new file mode 100644 index 000000000..75f7197ad --- /dev/null +++ b/Documentation/SetSPOContext.md @@ -0,0 +1,25 @@ +#Set-SPOContext +Sets the Client Context to use by the cmdlets +##Syntax +```powershell +Set-SPOContext -Context +``` + + +##Parameters +Parameter|Type|Required|Description +---------|----|--------|----------- +|Context|ClientContext|True|The ClientContext to set| +##Examples + +###Example 1 +```powershell +PS:> Connect-SPOnline -Url $siteAurl -Credentials $credentials +PS:> $ctx = Get-SPOContext +PS:> Get-SPOList # returns the lists from site specified with $siteAurl +PS:> Connect-SPOnline -Url $siteBurl -Credentials $credentials +PS:> Get-SPOList # returns the lists from the site specified with $siteBurl +PS:> Set-SPOContext -Context $ctx # switch back to site A +PS:> Get-SPOList # returns the lists from site A +``` + diff --git a/Documentation/SetSPOGroup.md b/Documentation/SetSPOGroup.md index ff6a6c4cd..3f9e59f8e 100644 --- a/Documentation/SetSPOGroup.md +++ b/Documentation/SetSPOGroup.md @@ -9,7 +9,7 @@ Set-SPOGroup -Identity [-SetAssociatedGroup ] [-RemoveRole ] [-Web ] -Identity +``` + + +##Parameters +Parameter|Type|Required|Description +---------|----|--------|----------- +|AddRole|String[]|False|Name of the permission set to add to this SharePoint group| +|Identity|GroupPipeBind|True|Get the permissions of a specific group by name| +|RemoveRole|String[]|False|Name of the permission set to remove from this SharePoint group| +|Web|WebPipeBind|False|The web to apply the command to. Omit this parameter to use the current web.| +##Examples + +###Example 1 +```powershell +PS:> Set-SPOGroupPermissions -Identity 'My Site Members' -AddRole Contribute +``` +Adds the 'Contribute' permission to the SharePoint group with the name 'My Site Members' + +###Example 2 +```powershell +PS:> Set-SPOGroupPermissions -Identity 'My Site Members' -RemoveRole 'Full Control' -AddRole 'Read' +``` +Removes the 'Full Control' from and adds the 'Contribute' permissions to the SharePoint group with the name 'My Site Members' + +###Example 3 +```powershell +PS:> Set-SPOGroupPermissions -Identity 'My Site Members' -AddRole @('Contribute', 'Design') +``` +Adds the 'Contribute' and 'Design' permissions to the SharePoint group with the name 'My Site Members' + +###Example 4 +```powershell +PS:> Set-SPOGroupPermissions -Identity 'My Site Members' -RemoveRole @('Contribute', 'Design') +``` +Removes the 'Contribute' and 'Design' permissions from the SharePoint group with the name 'My Site Members' diff --git a/Documentation/SetSPOListItem.md b/Documentation/SetSPOListItem.md new file mode 100644 index 000000000..ad3dd7f47 --- /dev/null +++ b/Documentation/SetSPOListItem.md @@ -0,0 +1,35 @@ +#Set-SPOListItem +Updates a list item +##Syntax +```powershell +Set-SPOListItem -Identity [-ContentType ] [-Values ] [-Web ] -List +``` + + +##Parameters +Parameter|Type|Required|Description +---------|----|--------|----------- +|ContentType|ContentTypePipeBind|False|Specify either the name, ID or an actual content type| +|Identity|ListItemPipeBind|True|The ID of the listitem, or actual ListItem object| +|List|ListPipeBind|True|The ID, Title or Url of the list.| +|Values|Hashtable|False|Use the internal names of the fields when specifying field names| +|Web|WebPipeBind|False|The web to apply the command to. Omit this parameter to use the current web.| +##Examples + +###Example 1 +```powershell +Set-SPOListItem -List "Demo List" -Identity 1 -Values @{"Title" = "Test Title"; "Category"="Test Category"} +``` +Sets fields value in the list item with ID 1 in the "Demo List". It sets both the Title and Category fields with the specified values. Notice, use the internal names of fields. + +###Example 2 +```powershell +Add-SPOListItem -List "Demo List" -Identity 1 -ContentType "Company" -Values @{"Title" = "Test Title"; "Category"="Test Category"} +``` +Sets fields value in the list item with ID 1 in the "Demo List". It sets the content type of the item to "Company" and it sets both the Title and Category fields with the specified values. Notice, use the internal names of fields. + +###Example 3 +```powershell +Add-SPOListItem -List "Demo List" -Identity $item -Values @{"Title" = "Test Title"; "Category"="Test Category"} +``` +Sets fields value in the list item which has been retrieved by for instance Get-SPOListItem.. It sets the content type of the item to "Company" and it sets both the Title and Category fields with the specified values. Notice, use the internal names of fields. diff --git a/Documentation/SetSPOListPermission.md b/Documentation/SetSPOListPermission.md index 288e08d13..9e440f970 100644 --- a/Documentation/SetSPOListPermission.md +++ b/Documentation/SetSPOListPermission.md @@ -20,3 +20,16 @@ Parameter|Type|Required|Description |RemoveRole|String|False|| |User|String|True|| |Web|WebPipeBind|False|The web to apply the command to. Omit this parameter to use the current web.| +##Examples + +###Example 1 +```powershell +PS:> Set-SPOListPermission -Identity 'Documents' -User 'user@contoso.com' -AddRole 'Contribute' +``` +Adds the 'Contribute' permission to the user 'user@contoso.com' for the list 'Documents' + +###Example 2 +```powershell +PS:> Set-SPOListPermission -Identity 'Documents' -User 'user@contoso.com' -RemoveRole 'Contribute' +``` +Removes the 'Contribute' permission to the user 'user@contoso.com' for the list 'Documents' diff --git a/Documentation/SetSPOSearchConfiguration.md b/Documentation/SetSPOSearchConfiguration.md index 77c14dba6..fbaf52299 100644 --- a/Documentation/SetSPOSearchConfiguration.md +++ b/Documentation/SetSPOSearchConfiguration.md @@ -1,5 +1,5 @@ #Set-SPOSearchConfiguration -Returns the search configuration +Sets the search configuration ##Syntax ```powershell Set-SPOSearchConfiguration -Configuration [-Scope ] [-Web ] diff --git a/Documentation/readme.md b/Documentation/readme.md index 129b7eac3..972334eb0 100644 --- a/Documentation/readme.md +++ b/Documentation/readme.md @@ -17,6 +17,7 @@ Cmdlet|Description **[Get‑SPOAuthenticationRealm](GetSPOAuthenticationRealm.md)** |Gets the authentication realm for the current web **[Get‑SPOAzureADManifestKeyCredentials](GetSPOAzureADManifestKeyCredentials.md)** |Creates the JSON snippet that is required for the manifest json file for Azure WebApplication / WebAPI apps **[Get‑SPOContext](GetSPOContext.md)** |Returns a Client Side Object Model context +**[Set‑SPOContext](SetSPOContext.md)** |Sets the Client Context to use by the cmdlets **[Get‑SPOHealthScore](GetSPOHealthScore.md)** |Retrieves the current health score value of the server **[Disconnect‑SPOnline](DisconnectSPOnline.md)** |Disconnects the context **[Connect‑SPOnline](ConnectSPOnline.md)** |Connects to a SharePoint site and creates an in-memory context @@ -96,6 +97,7 @@ Cmdlet|Description **[New‑SPOList](NewSPOList.md)** |Creates a new list **[Set‑SPOList](SetSPOList.md)** |Updates list settings **[Add‑SPOListItem](AddSPOListItem.md)** |Adds an item to a list +**[Set‑SPOListItem](SetSPOListItem.md)** |Updates a list item **[Get‑SPOListItem](GetSPOListItem.md)** |Retrieves list items **[Set‑SPOListPermission](SetSPOListPermission.md)** |Sets list permissions **[Request‑SPOReIndexList](RequestSPOReIndexList.md)** |Marks the list for full indexing during the next incremental crawl @@ -116,12 +118,14 @@ Cmdlet|Description ##Search Cmdlet|Description :-----|:---------- -**[Set‑SPOSearchConfiguration](SetSPOSearchConfiguration.md)** |Returns the search configuration +**[Set‑SPOSearchConfiguration](SetSPOSearchConfiguration.md)** |Sets the search configuration **[Get‑SPOSearchConfiguration](GetSPOSearchConfiguration.md)** |Returns the search configuration ##Sites Cmdlet|Description :-----|:---------- **[Set‑SPOAppSideLoading](SetSPOAppSideLoading.md)** |Enables the App Side Loading Feature on a site +**[Get‑SPOAuditing](GetSPOAuditing.md)** |Get the Auditing setting of a site +**[Set‑SPOAuditing](SetSPOAuditing.md)** |Set Auditing setting for a site **[Get‑SPOSite](GetSPOSite.md)** |Returns the current site collection from the context. **[Uninstall‑SPOSolution](UninstallSPOSolution.md)** |Uninstalls a sandboxed solution from a site collection **[Install‑SPOSolution](InstallSPOSolution.md)** |Installs a sandboxed solution to a site collection. WARNING! This method can delete your composed look gallery due to the method used to activate the solution. We recommend you to only to use this cmdlet if you are okay with that. @@ -154,6 +158,8 @@ Cmdlet|Description **[Set‑SPOGroup](SetSPOGroup.md)** |Updates a group **[New‑SPOGroup](NewSPOGroup.md)** |Adds a user to the build-in Site User Info List and returns a user object **[Get‑SPOGroup](GetSPOGroup.md)** |Returns a specific group or all groups. +**[Set‑SPOGroupPermissions](SetSPOGroupPermissions.md)** |Adds and/or removes permissions of a specific SharePoint group +**[Get‑SPOGroupPermissions](GetSPOGroupPermissions.md)** |Returns the permissions for a specific SharePoint group **[New‑SPOUser](NewSPOUser.md)** |Adds a user to the build-in Site User Info List and returns a user object **[Remove‑SPOUserFromGroup](RemoveSPOUserFromGroup.md)** |Removes a user from a group **[Add‑SPOUserToGroup](AddSPOUserToGroup.md)** |Adds a user to a group diff --git a/OfficeDevPnP.PowerShell.sln b/OfficeDevPnP.PowerShell.sln index da6fc68f3..83d7caac3 100644 --- a/OfficeDevPnP.PowerShell.sln +++ b/OfficeDevPnP.PowerShell.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 +VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OfficeDevPnP.PowerShell.Commands", "Commands\OfficeDevPnP.PowerShell.Commands.csproj", "{1DDE6F0A-CA49-419A-9CE8-A6CA02F43CE0}" EndProject @@ -18,6 +18,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documentation", "Documentation", "{AB70588E-5972-4D9B-9342-C8CA3275F80A}" ProjectSection(SolutionItems) = preProject changelog.md = changelog.md + CONTRIBUTING.md = CONTRIBUTING.md readme.md = readme.md EndProjectSection EndProject diff --git a/README.md b/README.md index f512442bf..88fdb992a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This solution shows how you can build a library of PowerShell commands that act - SharePoint 2013 on-premises ### Prerequisites ### -In order to build the setup project the WiX toolset needs to be installed. You can obtain this from http://wix.codeplex.com. If you use Visual Studio 2015 you will need at least WiX 3.10, which can be downloaded from here: http://wixtoolset.org/releases/ +In order to build the setup project the WiX toolset needs to be installed. You can obtain this from http://wix.codeplex.com. If you use Visual Studio 2015 you will need at least WiX 3.10, but do not install WiX v4.x, which can be downloaded from here: http://wixtoolset.org/releases/ In order to generate the Cmdlet help you need Windows Management Framework v4.0 which you can download from http://www.microsoft.com/en-us/download/details.aspx?id=40855 @@ -109,3 +109,7 @@ Connect-SPOnline –Url https://yoursite.sharepoint.com –Credentials yourlabel Alternatively you can create a credential manager entry with an internet or network address starting with your tenant url, e.g. https://mytenant.sharepoint.com. If you then use Connect-SPOnline -Url https://mytenant.sharepoint.com/sites/yoursite to create a new connection, the cmdlet will resolve the credentials to use based upon the URL. + +# Contributing # + +If you want to contribute to this OfficeDevPnP PowerShel library, please [proceed here](CONTRIBUTING.md) diff --git a/Setup/Product.wxs b/Setup/Product.wxs index 09549952b..0543ea982 100644 --- a/Setup/Product.wxs +++ b/Setup/Product.wxs @@ -16,7 +16,7 @@ diff --git a/Tests/OfficeDevPnP.PowerShell.Tests.csproj b/Tests/OfficeDevPnP.PowerShell.Tests.csproj index 18a1446fc..13aa4645c 100644 --- a/Tests/OfficeDevPnP.PowerShell.Tests.csproj +++ b/Tests/OfficeDevPnP.PowerShell.Tests.csproj @@ -57,55 +57,55 @@ False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.Office.Client.Policy.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.Office.Client.Policy.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.Office.Client.TranslationServices.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.Office.Client.TranslationServices.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.Online.SharePoint.Client.Tenant.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.Online.SharePoint.Client.Tenant.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.DocumentManagement.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.DocumentManagement.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.Publishing.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.Publishing.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.Runtime.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.Runtime.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.Search.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.Search.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.Search.Applications.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.Search.Applications.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.Taxonomy.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.Taxonomy.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.UserProfiles.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.UserProfiles.dll False - ..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.WorkflowServices.dll + ..\..\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.WorkflowServices.dll False - ..\ReferenceAssemblies\16\Microsoft.Office.Client.Education.dll + ..\ReferenceAssemblies\16.1\Microsoft.Office.Client.Education.dll diff --git a/Tests/PSTestScope.cs b/Tests/PSTestScope.cs index 65c4ff13a..993720e29 100644 --- a/Tests/PSTestScope.cs +++ b/Tests/PSTestScope.cs @@ -14,11 +14,17 @@ public class PSTestScope : IDisposable public string SiteUrl { get; set; } public string CredentialManagerEntry { get; set; } + public string Realm { get; set; } + public string AppId { get; set; } + public string AppSecret { get; set; } public PSTestScope(bool connect = true) { SiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"]; CredentialManagerEntry = ConfigurationManager.AppSettings["SPOCredentialManagerLabel"]; + Realm = ConfigurationManager.AppSettings["Realm"]; + AppId = ConfigurationManager.AppSettings["AppId"]; + AppSecret = ConfigurationManager.AppSettings["AppSecret"]; var iss = InitialSessionState.CreateDefault(); if (connect) @@ -39,8 +45,19 @@ public PSTestScope(bool connect = true) cmd.Parameters.Add("Url", SiteUrl); if (!string.IsNullOrEmpty(CredentialManagerEntry)) { + // Use Windows Credential Manager to authenticate cmd.Parameters.Add("Credentials", CredentialManagerEntry); } + else + { + if (!string.IsNullOrEmpty(Realm) && !string.IsNullOrEmpty("AppId") && !string.IsNullOrEmpty("AppSecret")) + { + // Use oAuth Token to authenticate + cmd.Parameters.Add("Realm", Realm); + cmd.Parameters.Add("AppId", AppId); + cmd.Parameters.Add("AppSecret", AppSecret); + } + } pipeLine.Commands.Add(cmd); pipeLine.Invoke(); } diff --git a/changelog.md b/changelog.md index ced74f484..3bdce5114 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,17 @@ # OfficeDevPnP.PowerShell Changelog # +**2015-21-26** + +* Added -AsIncludeFile parameter to New-SPOProvisioningTemplateFromFolder + +**2015-12-21** + +* Added a Set-SPOContext cmdlet + +**2015-12-14** + +* Added Set-SPOListItem cmdlet + **2015-11-21** * Added, where applicable, Site Relative Url parameters, besides the existing Server Relative Url parameters on cmdlets.