Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.

Commit 0685601

Browse files
Merge pull request #488 from OfficeDev/dev
October 2016 Release
2 parents 6be4b4e + 2b97ffc commit 0685601

File tree

139 files changed

+1598
-377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+1598
-377
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
###Notice: many issues / bugs reported are actually related to the PnP Core Library which is used behind the scenes. Consider carefully where to report an issue:###
22

3-
1. Is the issue related to Apply-SPOProvisioningTemplate or Get-SPOProvisioningTemplate? Then report the issue here: https://github.com/officedev/PnP-Sites-Core/issues. Those cmdlets are merely thin wrappers around the code provided there and your issue has a greater chance of being handled correctly when you report it in that repository.
4-
2. Is the issue related to the cmdlet itself, its parameters, the syntax, or do you suspect it's the code of the cmdlet that is causing the issue? Then please continue reporting the issue here.
5-
3. If you think that the functionality might be related to the underlying libraries that the cmdlet is calling (We realize that that might be difficult to determine), please first double check the code of the cmdlet, which can be found here: https://github.com/OfficeDev/PnP-PowerShell/tree/master/Commands. If related to the cmdlet, continue reporting the issue here, otherwise report the issue at https://github.com/officedev/PnP-Sites-Core/issues
3+
1. **Are you using ```Apply-SPOProvisioningTemplate``` or ```Get-SPOProvisioningTemplate```**? The issue is most likely related to the Provisioning Engine. The Provisioning engine is _not_ located in the PowerShell repo. Please report the issue here: https://github.com/officedev/PnP-Sites-Core/issues.
4+
2. **Is the issue related to the cmdlet itself, its parameters, the syntax, or do you suspect it's the code of the cmdlet that is causing the issue?** Then please continue reporting the issue in this repo.
5+
3. **If you think that the functionality might be related to the underlying libraries that the cmdlet is calling** (We realize that that might be difficult to determine), please first double check the code of the cmdlet, which can be found here: https://github.com/OfficeDev/PnP-PowerShell/tree/master/Commands. If related to the cmdlet, continue reporting the issue here, otherwise report the issue at https://github.com/officedev/PnP-Sites-Core/issues
66

77
### Reporting an Issue or Missing Feature
88
Please confirm what it is that your reporting
@@ -16,8 +16,16 @@ Please describe what you see instead. Please provide samples of HTML output or s
1616
### Steps to reproduce behavior
1717
Please include complete code samples in-line or linked from [gists](https://gist.github.com/)
1818

19-
### What version of the PnP-PowerShell Cmdlets are you using?
20-
Example: March PnP-PowerShell SharePoint Online (V16), December PnP-PowerShell SharePoint On-Premises (V15)
19+
### Which version of the PnP-PowerShell Cmdlets are you using?
20+
- [ ] PnP PowerShell for SharePoint 2013
21+
- [ ] PnP PowerShell for SharePoint 2016
22+
- [ ] PnP PowerShell for SharePoint Online
23+
24+
### What is the version of the Cmdlet module you are running?
25+
(you can retrieve this by executing ```Get-Module -Name *pnppowershell* -ListAvailable```)
2126

2227
### How did you install the PnP-PowerShell Cmdlets?
23-
Example: Via MSI installer, From the PowerShell Gallery, other
28+
- [ ] MSI Installed downloaded from GitHub
29+
- [ ] Installed through the PowerShell Gallery with Install-Module
30+
- [ ] Other means
31+

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Type ##
2+
- [ ] Bug Fix
3+
- [ ] New Feature
4+
- [ ] Sample
5+
6+
## Related Issues? ##
7+
Fixes #X, partially fixes #Y, mentioned in #Z, etc.
8+
9+
## What is in this Pull Request ? ##
10+
Please describe the changes in the PR.
11+
12+
### Guidance ###
13+
* You can delete this section when you are submitting the pull request.*
14+
* *Please update this PR information accordingly. We use this as part of our release notes in monthly communications.*
15+
* **Please target your PR to Dev branch. If you do not target the Dev branch we will not accept this PR.**
12 KB
Binary file not shown.
12 KB
Binary file not shown.
8 KB
Binary file not shown.

Commands/Base/ExecuteQuery.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ namespace SharePointPnP.PowerShell.Commands.Base
1010
[CmdletExample(
1111
Code = @"PS:> Execute-SPOQuery -RetryCount 5",
1212
Remarks = @"This will execute any queued actions / changes on the SharePoint Client Side Object Model Context and will retry 5 times in case of throttling.", SortOrder = 1)]
13+
[CmdletExample(
14+
Code = @"PS:> Execute-SPOQuery -RetryWait 10",
15+
Remarks = @"This will execute any queued actions / changes on the SharePoint Client Side Object Model Context and delay the execution with 10 seconds when it needs to retry the execution.", SortOrder = 2)]
1316

1417
public class ExecuteSPOQuery : SPOCmdlet
1518
{

Commands/Base/GetStoredCredential.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ namespace SharePointPnP.PowerShell.Commands.Base
1111
[CmdletExample(Code = "PS:> Get-SPOnlineStoredCredential -Name O365",
1212
Remarks = "Returns the credential associated with the specified identifier",
1313
SortOrder = 1)]
14+
[CmdletExample(Code = "PS:> Get-SPOnlineStoredCredential -Name testEnvironment -Type OnPrem",
15+
Remarks = "Gets the credential associated with the specified identifier from the credential manager and then will return a credential that can be used for on-premises authentication",
16+
SortOrder = 2)]
1417
public class GetStoredCredential : PSCmdlet
1518
{
1619
[Parameter(Mandatory = true, HelpMessage = "The credential to retrieve.")]

Commands/Base/SPOnlineConnectionHelper.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,16 @@ internal static SPOnlineConnection InstantiateSPOnlineConnection(Uri url, string
3535
realm = GetRealmFromTargetUrl(url);
3636
}
3737

38-
var context = PnPClientContext.ConvertFrom(authManager.GetAppOnlyAuthenticatedContext(url.ToString(), realm, clientId, clientSecret), retryCount, retryWait * 1000);
38+
PnPClientContext context = null;
39+
if (url.DnsSafeHost.Contains("spoppe.com"))
40+
{
41+
context = PnPClientContext.ConvertFrom(authManager.GetAppOnlyAuthenticatedContext(url.ToString(), realm, clientId, clientSecret, acsHostUrl: "windows-ppe.net", globalEndPointPrefix: "login"), retryCount, retryWait * 1000);
42+
}
43+
else
44+
{
45+
context = PnPClientContext.ConvertFrom(authManager.GetAppOnlyAuthenticatedContext(url.ToString(), realm, clientId, clientSecret), retryCount, retryWait * 1000);
46+
}
47+
3948
context.ApplicationName = Properties.Resources.ApplicationName;
4049
context.RequestTimeout = requestTimeout;
4150
#if !ONPREMISES

Commands/Branding/AddCustomAction.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,51 @@ namespace SharePointPnP.PowerShell.Commands.Branding
1010
[CmdletHelp("Adds a custom action to a web", Category = CmdletHelpCategory.Branding)]
1111
[CmdletExample(Code = @"$cUIExtn = ""<CommandUIExtension><CommandUIDefinitions><CommandUIDefinition Location=""""Ribbon.List.Share.Controls._children""""><Button Id=""""Ribbon.List.Share.GetItemsCountButton"""" Alt=""""Get list items count"""" Sequence=""""11"""" Command=""""Invoke_GetItemsCountButtonRequest"""" LabelText=""""Get Items Count"""" TemplateAlias=""""o1"""" Image32by32=""""_layouts/15/images/placeholder32x32.png"""" Image16by16=""""_layouts/15/images/placeholder16x16.png"""" /></CommandUIDefinition></CommandUIDefinitions><CommandUIHandlers><CommandUIHandler Command=""""Invoke_GetItemsCountButtonRequest"""" CommandAction=""""javascript: alert('Total items in this list: '+ ctx.TotalListItems);"""" EnabledScript=""""javascript: function checkEnable() { return (true);} checkEnable();""""/></CommandUIHandlers></CommandUIExtension>""
1212
13-
Add-SPOCustomAction -Name 'GetItemsCount' -Title 'Invoke GetItemsCount Action' -Description 'Adds custom action to custom list ribbon' -Group 'Microsoft.SharePoint.Client.UserCustomAction.group' -Location 'CommandUI.Ribbon' -CommandUIExtension $cUIExtn",
13+
Add-SPOCustomAction -Name 'GetItemsCount' -Title 'Invoke GetItemsCount Action' -Description 'Adds custom action to custom list ribbon' -Group 'SiteActions' -Location 'CommandUI.Ribbon' -CommandUIExtension $cUIExtn",
1414
Remarks = @"Adds a new custom action to the custom list template, and sets the Title, Name and other fields with the specified values. On click it shows the number of items in that list. Notice: escape quotes in CommandUIExtension.",
1515
SortOrder = 1)]
16+
[CmdletRelatedLink(
17+
Text ="UserCustomAction",
18+
Url = "https://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.client.usercustomaction.aspx")]
19+
[CmdletRelatedLink(
20+
Text ="BasePermissions",
21+
Url = "https://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.client.basepermissions.aspx")]
1622
public class AddCustomAction : SPOWebCmdlet
1723
{
18-
[Parameter(Mandatory = true)]
24+
[Parameter(Mandatory = true, HelpMessage = "The name of the custom action")]
1925
public string Name = string.Empty;
2026

21-
[Parameter(Mandatory = true)]
27+
[Parameter(Mandatory = true, HelpMessage = "The title of the custom action")]
2228
public string Title = string.Empty;
2329

24-
[Parameter(Mandatory = true)]
30+
[Parameter(Mandatory = true, HelpMessage = "The description of the custom action")]
2531
public string Description = string.Empty;
2632

27-
[Parameter(Mandatory = true)]
33+
[Parameter(Mandatory = true, HelpMessage = "The group where this custom action needs to be added like 'SiteActions'")]
2834
public string Group = string.Empty;
2935

30-
[Parameter(Mandatory = true)]
36+
[Parameter(Mandatory = true, HelpMessage = "The actual location where this custom action need to be added like 'CommandUI.Ribbon'")]
3137
public string Location = string.Empty;
3238

3339
[Parameter(Mandatory = false, HelpMessage = "Sequence of this CustomAction being injected. Use when you have a specific sequence with which to have multiple CustomActions being added to the page.")]
3440
public int Sequence = 0;
3541

36-
[Parameter(Mandatory = false)]
42+
[Parameter(Mandatory = false, HelpMessage = "The URL, URI or ECMAScript (JScript, JavaScript) function associated with the action")]
3743
public string Url = string.Empty;
3844

39-
[Parameter(Mandatory = false)]
45+
[Parameter(Mandatory = false, HelpMessage = "The URL of the image associated with the custom action")]
4046
public string ImageUrl = string.Empty;
4147

42-
[Parameter(Mandatory = false)]
48+
[Parameter(Mandatory = false, HelpMessage = "XML fragment that determines user interface properties of the custom action")]
4349
public string CommandUIExtension = string.Empty;
4450

45-
[Parameter(Mandatory = false)]
51+
[Parameter(Mandatory = false, HelpMessage = "The identifier of the object associated with the custom action.")]
4652
public string RegistrationId = string.Empty;
4753

48-
[Parameter(Mandatory = false)]
54+
[Parameter(Mandatory = false, HelpMessage = "A string array that contain the permissions needed for the custom action")]
4955
public PermissionKind[] Rights;
5056

51-
[Parameter(Mandatory = false)]
57+
[Parameter(Mandatory = false, HelpMessage = "Specifies the type of object associated with the custom action")]
5258
public UserCustomActionRegistrationType RegistrationType;
5359

5460
[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.")]
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using OfficeDevPnP.Core.Framework.Provisioning.Connectors;
2+
using OfficeDevPnP.Core.Framework.Provisioning.Model;
3+
using OfficeDevPnP.Core.Framework.Provisioning.Providers;
4+
using OfficeDevPnP.Core.Framework.Provisioning.Providers.Xml;
5+
using SharePointPnP.PowerShell.CmdletHelpAttributes;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.IO;
9+
using System.Linq;
10+
using System.Management.Automation;
11+
using System.Text;
12+
using System.Threading.Tasks;
13+
14+
namespace SharePointPnP.PowerShell.Commands.Branding
15+
{
16+
[Cmdlet("Add", "SPOFileToProvisioningTemplate")]
17+
[CmdletHelp("Adds a file to an in-memory PnP Provisioning Template",
18+
Category = CmdletHelpCategory.Branding)]
19+
[CmdletExample(
20+
Code = @"PS:> Add-SPOFileToProvisioningTemplate -Path template.pnp -Source $sourceFilePath -Folder $targetFolder",
21+
Remarks = "Adds a file to an in-memory PnP Provisioning Template",
22+
SortOrder = 1)]
23+
[CmdletExample(
24+
Code = @"PS:> Add-SPOFileToProvisioningTemplate -Path template.pnp -Source $sourceFilePath -Folder $targetFolder -Container $container",
25+
Remarks = "Adds a file to an in-memory PnP Provisioning Template with a custom container for the file",
26+
SortOrder = 2)]
27+
public class AddFileToProvisioningTemplate : PSCmdlet
28+
{
29+
[Parameter(Mandatory = true, Position = 0, HelpMessage = "Filename of the .PNP Open XML provisioning template to read from, optionally including full path.")]
30+
public string Path;
31+
32+
[Parameter(Mandatory = true, Position = 1, HelpMessage = "The file to add to the in-memory template, optionally including full path.")]
33+
public string Source;
34+
35+
[Parameter(Mandatory = true, Position = 2, HelpMessage = "The target Folder for the file to add to the in-memory template.")]
36+
public string Folder;
37+
38+
[Parameter(Mandatory = false, Position = 3, HelpMessage = "The target Container for the file to add to the in-memory template, optional argument.")]
39+
public string Container;
40+
41+
[Parameter(Mandatory = false, Position = 4, HelpMessage = "Allows you to specify ITemplateProviderExtension to execute while loading the template.")]
42+
public ITemplateProviderExtension[] TemplateProviderExtensions;
43+
44+
protected override void ProcessRecord()
45+
{
46+
if (String.IsNullOrEmpty(Source))
47+
{
48+
throw new ArgumentNullException("Source");
49+
}
50+
51+
if (String.IsNullOrEmpty(Folder))
52+
{
53+
throw new ArgumentNullException("Folder");
54+
}
55+
56+
// Load the template
57+
ProvisioningTemplate template = LoadProvisioningTemplate
58+
.LoadProvisioningTemplateFromFile(Path,
59+
SessionState.Path.CurrentFileSystemLocation.Path,
60+
TemplateProviderExtensions);
61+
62+
if (template == null)
63+
{
64+
throw new ApplicationException("Invalid template file!");
65+
}
66+
67+
// Load the file and add it to the .PNP file
68+
using (FileStream fs = new FileStream(Source, FileMode.Open, FileAccess.Read, FileShare.Read))
69+
{
70+
Folder = Folder.Replace("\\", "/");
71+
72+
String fileName = Source.IndexOf("\\") > 0 ? Source.Substring(Source.LastIndexOf("\\") + 1) : Source;
73+
String container = !String.IsNullOrEmpty(Container) ? Container : String.Empty;
74+
String source = !String.IsNullOrEmpty(container) ? (container + "/" + fileName) : fileName;
75+
76+
template.Connector.SaveFileStream(fileName, container, fs);
77+
78+
if (template.Connector is ICommitableFileConnector)
79+
{
80+
((ICommitableFileConnector)template.Connector).Commit();
81+
}
82+
83+
template.Files.Add(new OfficeDevPnP.Core.Framework.Provisioning.Model.File {
84+
Src = source,
85+
Folder = Folder,
86+
Overwrite = true,
87+
});
88+
89+
// Determine the output file name and path
90+
string outFileName = System.IO.Path.GetFileName(Path);
91+
string outPath = new System.IO.FileInfo(Path).DirectoryName;
92+
93+
// Save the template back to the storage
94+
var fileSystemConnector = new FileSystemConnector(outPath, "");
95+
ITemplateFormatter formatter = XMLPnPSchemaFormatter.LatestFormatter;
96+
97+
XMLTemplateProvider provider = new XMLOpenXMLTemplateProvider(
98+
Path, fileSystemConnector);
99+
var templateFileName = outFileName.Substring(0, outFileName.LastIndexOf(".", StringComparison.Ordinal)) + ".xml";
100+
101+
provider.SaveAs(template, templateFileName, formatter, TemplateProviderExtensions);
102+
}
103+
}
104+
}
105+
}

Commands/Branding/AddJavaScriptBlock.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ namespace SharePointPnP.PowerShell.Commands.Branding
1010
[CmdletHelp("Adds a link to a JavaScript snippet/block to a web or site collection",
1111
DetailedDescription = "Specify a scope as 'Site' to add the custom action to all sites in a site collection.",
1212
Category = CmdletHelpCategory.Branding)]
13+
[CmdletExample(Code = "PS:> Add-SPOJavaScriptBlock -Name myAction -script '<script>Alert(\"This is my Script block\");</script>' -Sequence 9999 -Scope Site",
14+
Remarks = "Add a JavaScript code block to all pages within the current site collection under the name myAction and at order 9999",
15+
SortOrder = 1)]
16+
[CmdletExample(Code = "PS:> Add-SPOJavaScriptBlock -Name myAction -script '<script>Alert(\"This is my Script block\");</script>'",
17+
Remarks = "Add a JavaScript code block to all pages within the current web under the name myAction",
18+
SortOrder = 2)]
1319
public class AddJavaScriptBlock : SPOWebCmdlet
1420
{
1521
[Parameter(Mandatory = true, HelpMessage = "The name of the script block. Can be used to identify the script with other cmdlets or coded solutions")]
1622
[Alias("Key")]
1723
public string Name = string.Empty;
1824

19-
[Parameter(Mandatory = true, HelpMessage = "The javascript block to add")]
25+
[Parameter(Mandatory = true, HelpMessage = "The javascript block to add to the specified scope")]
2026
public string Script = null;
2127

22-
[Parameter(Mandatory = false)]
28+
[Parameter(Mandatory = false, HelpMessage = "A sequence number that defines the order on the page")]
2329
public int Sequence = 0;
2430

2531
[Parameter(Mandatory = false)]
@@ -32,7 +38,7 @@ public class AddJavaScriptBlock : SPOWebCmdlet
3238

3339
protected override void ExecuteCmdlet()
3440
{
35-
// Following code to handle desprecated parameter
41+
// Following code to handle deprecated parameter
3642
CustomActionScope setScope;
3743

3844
if (MyInvocation.BoundParameters.ContainsKey("SiteScoped"))
@@ -44,14 +50,21 @@ protected override void ExecuteCmdlet()
4450
setScope = Scope;
4551
}
4652

47-
if (setScope == CustomActionScope.Web)
53+
if (setScope != CustomActionScope.All)
4854
{
49-
SelectedWeb.AddJsBlock(Name, Script, Sequence);
55+
if (setScope == CustomActionScope.Web)
56+
{
57+
SelectedWeb.AddJsBlock(Name, Script, Sequence);
58+
}
59+
else
60+
{
61+
var site = ClientContext.Site;
62+
site.AddJsBlock(Name, Script, Sequence);
63+
}
5064
}
5165
else
5266
{
53-
var site = ClientContext.Site;
54-
site.AddJsBlock(Name, Script, Sequence);
67+
WriteError(new ErrorRecord(new Exception("Scope parameter can only be set to Web or Site"),"INCORRECTVALUE",ErrorCategory.InvalidArgument, this));
5568
}
5669
}
5770
}

Commands/Branding/AddJavaScriptLink.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected override void ExecuteCmdlet()
6060
break;
6161

6262
case CustomActionScope.All:
63-
WriteWarning("CustomActionScope All is not supported for adding JavaScriptLinks");
63+
WriteError(new ErrorRecord(new Exception("Scope parameter can only be set to Web or Site"), "INCORRECTVALUE", ErrorCategory.InvalidArgument, this));
6464
break;
6565
}
6666
}

0 commit comments

Comments
 (0)