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

Commit c1cacc5

Browse files
committed
Merge pull request #205 from OfficeDev/dev
January 2016 Release
2 parents a20c761 + 0cc7052 commit c1cacc5

File tree

77 files changed

+1461
-371
lines changed

Some content is hidden

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

77 files changed

+1461
-371
lines changed

Binaries/PnPPowerShellCommands15.msi

104 KB
Binary file not shown.

Binaries/PnPPowerShellCommands16.msi

124 KB
Binary file not shown.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Please see following page for additional insights on the model.
3030

3131

3232
##Code contributions
33-
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
33+
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
3434
compile it, make sure that PnP-Sites-Core is located at the same level as PnP-PowerShell.
3535

3636
So:

CmdletHelpGenerator/Program.cs

Lines changed: 151 additions & 124 deletions
Large diffs are not rendered by default.

Commands/Base/ConnectSPOnline.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public class ConnectSPOnline : PSCmdlet
6767
[Parameter(Mandatory = true, ParameterSetName = "Token", HelpMessage = "The Application Client Secret to use.")]
6868
public string AppSecret;
6969

70+
[Parameter(Mandatory = true, ParameterSetName = "Weblogin", HelpMessage = "If you want to connect to SharePoint with browser based login")]
71+
public SwitchParameter UseWebLogin;
72+
7073
#if !CLIENTSDKV15
7174
[Parameter(Mandatory = true, ParameterSetName = "NativeAAD", HelpMessage = "The Client ID of the Azure AD Application")]
7275
[Parameter(Mandatory = true, ParameterSetName = "AppOnlyAAD", HelpMessage = "The Client ID of the Azure AD Application")]
@@ -102,6 +105,10 @@ protected override void ProcessRecord()
102105
{
103106
SPOnlineConnection.CurrentConnection = SPOnlineConnectionHelper.InstantiateSPOnlineConnection(new Uri(Url), Realm, AppId, AppSecret, Host, MinimalHealthScore, RetryCount, RetryWait, RequestTimeout, SkipTenantAdminCheck);
104107
}
108+
else if(UseWebLogin)
109+
{
110+
SPOnlineConnection.CurrentConnection = SPOnlineConnectionHelper.InstantiateWebloginConnection(new Uri(Url), MinimalHealthScore, RetryCount, RetryWait, RequestTimeout, SkipTenantAdminCheck);
111+
}
105112
else if (UseAdfs)
106113
{
107114
creds = GetCredentials();
File renamed without changes.

Commands/Base/GetContext.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Management.Automation;
2+
using OfficeDevPnP.PowerShell.CmdletHelpAttributes;
3+
using System;
4+
using OfficeDevPnP.PowerShell.Commands.Properties;
5+
6+
namespace OfficeDevPnP.PowerShell.Commands.Base
7+
{
8+
[Cmdlet(VerbsCommon.Get, "SPOContext")]
9+
[CmdletHelp("Returns a Client Side Object Model context",
10+
Category = CmdletHelpCategory.Base)]
11+
public class GetSPOContext : PSCmdlet
12+
{
13+
14+
protected override void BeginProcessing()
15+
{
16+
base.BeginProcessing();
17+
18+
if (SPOnlineConnection.CurrentConnection == null)
19+
{
20+
throw new InvalidOperationException(Resources.NoConnection);
21+
}
22+
if (SPOnlineConnection.CurrentConnection.Context == null)
23+
{
24+
throw new InvalidOperationException(Resources.NoConnection);
25+
}
26+
}
27+
28+
protected override void ProcessRecord()
29+
{
30+
WriteObject(SPOnlineConnection.CurrentConnection.Context);
31+
}
32+
}
33+
}

Commands/Base/GetSPOContext.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using Microsoft.SharePoint.Client;
2+
using System;
3+
4+
namespace OfficeDevPnP.PowerShell.Commands.Base.PipeBinds
5+
{
6+
public sealed class ListItemPipeBind
7+
{
8+
private readonly ListItem _item;
9+
private readonly uint _id;
10+
11+
public ListItemPipeBind()
12+
{
13+
_item = null;
14+
_id = uint.MinValue;
15+
}
16+
17+
public ListItemPipeBind(ListItem item)
18+
{
19+
_item = item;
20+
}
21+
22+
public ListItemPipeBind(string id)
23+
{
24+
uint uintId;
25+
26+
if (uint.TryParse(id, out uintId))
27+
{
28+
_id = uintId;
29+
}
30+
else
31+
{
32+
_id = uint.MinValue;
33+
}
34+
}
35+
36+
public ListItem Item
37+
{
38+
get
39+
{
40+
return _item;
41+
}
42+
}
43+
44+
public uint Id
45+
{
46+
get { return _id; }
47+
}
48+
49+
internal ListItem GetListItem(List list)
50+
{
51+
ListItem item = null;
52+
if (_id != uint.MinValue)
53+
{
54+
item = list.GetItemById((int)_id);
55+
}
56+
if (item == null && _item != null)
57+
{
58+
item = _item;
59+
}
60+
61+
if (item != null)
62+
{
63+
list.Context.Load(item);
64+
list.Context.ExecuteQueryRetry();
65+
}
66+
return item;
67+
}
68+
}
69+
}

Commands/Base/SPOWebCmdlet.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private Web GetWeb()
6161
web = ClientContext.Web;
6262
}
6363

64+
SPOnlineConnection.CurrentConnection.Context.ExecuteQueryRetry();
6465

6566
return web;
6667
}

Commands/Base/SPOnlineConnectionHelper.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ internal static SPOnlineConnection InstantiateSPOnlineConnection(Uri url, string
5858
return new SPOnlineConnection(context, connectionType, minimalHealthScore, retryCount, retryWait, null, url.ToString());
5959
}
6060

61+
6162
#if !CLIENTSDKV15
6263
internal static SPOnlineConnection InitiateAzureADNativeApplicationConnection(Uri url, string clientId, Uri redirectUri, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, bool skipAdminCheck = false)
6364
{
@@ -106,6 +107,34 @@ internal static SPOnlineConnection InitiateAzureADAppOnlyConnection(Uri url, str
106107
}
107108
#endif
108109

110+
internal static SPOnlineConnection InstantiateWebloginConnection(Uri url, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, bool skipAdminCheck = false)
111+
{
112+
var authManager = new Core.AuthenticationManager();
113+
114+
var context = authManager.GetWebLoginClientContext(url.ToString());
115+
116+
if (context != null)
117+
{
118+
context.ApplicationName = Properties.Resources.ApplicationName;
119+
context.RequestTimeout = requestTimeout;
120+
var connectionType = ConnectionType.OnPrem;
121+
if (url.Host.ToUpperInvariant().EndsWith("SHAREPOINT.COM"))
122+
{
123+
connectionType = ConnectionType.O365;
124+
}
125+
if (skipAdminCheck == false)
126+
{
127+
if (IsTenantAdminSite(context))
128+
{
129+
connectionType = ConnectionType.TenantAdmin;
130+
}
131+
}
132+
133+
return new SPOnlineConnection(context, connectionType, minimalHealthScore, retryCount, retryWait, null, url.ToString());
134+
}
135+
throw new Exception("Error establishing a connection, context is null");
136+
}
137+
109138
internal static SPOnlineConnection InstantiateSPOnlineConnection(Uri url, PSCredential credentials, PSHost host, bool currentCredentials, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, bool skipAdminCheck = false)
110139
{
111140
ClientContext context = new ClientContext(url.AbsoluteUri);

Commands/Base/SetContext.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Management.Automation;
2+
using OfficeDevPnP.PowerShell.CmdletHelpAttributes;
3+
using Microsoft.SharePoint.Client;
4+
5+
namespace OfficeDevPnP.PowerShell.Commands.Base
6+
{
7+
[Cmdlet(VerbsCommon.Set, "SPOContext")]
8+
[CmdletHelp("Sets the Client Context to use by the cmdlets",
9+
Category = CmdletHelpCategory.Base)]
10+
[CmdletExample(
11+
Code = @"PS:> Connect-SPOnline -Url $siteAurl -Credentials $credentials
12+
PS:> $ctx = Get-SPOContext
13+
PS:> Get-SPOList # returns the lists from site specified with $siteAurl
14+
PS:> Connect-SPOnline -Url $siteBurl -Credentials $credentials
15+
PS:> Get-SPOList # returns the lists from the site specified with $siteBurl
16+
PS:> Set-SPOContext -Context $ctx # switch back to site A
17+
PS:> Get-SPOList # returns the lists from site A", SortOrder = 1)]
18+
public class SetContext : PSCmdlet
19+
{
20+
[Parameter(Mandatory = true, ValueFromPipeline = true, Position = 1, HelpMessage = "The ClientContext to set")]
21+
public ClientContext Context;
22+
23+
protected override void ProcessRecord()
24+
{
25+
SPOnlineConnection.CurrentConnection.Context = Context;
26+
}
27+
}
28+
}

Commands/Branding/AddCustomAction.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class AddCustomAction : SPOWebCmdlet
3232
[Parameter(Mandatory = true)]
3333
public string Location = string.Empty;
3434

35-
[Parameter(Mandatory = false)]
35+
[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.")]
3636
public int Sequence = 0;
3737

3838
[Parameter(Mandatory = false)]
@@ -53,10 +53,9 @@ public class AddCustomAction : SPOWebCmdlet
5353
[Parameter(Mandatory = false)]
5454
public UserCustomActionRegistrationType RegistrationType;
5555

56-
[Parameter(Mandatory = false)]
56+
[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.")]
5757
public CustomActionScope Scope = CustomActionScope.Web;
5858

59-
6059
protected override void ExecuteCmdlet()
6160
{
6261
var permissions = new BasePermissions();
@@ -84,14 +83,20 @@ protected override void ExecuteCmdlet()
8483
Rights = permissions
8584
};
8685

87-
if (Scope == CustomActionScope.Web)
86+
switch (Scope)
8887
{
89-
SelectedWeb.AddCustomAction(ca);
90-
}
91-
else
92-
{
93-
ClientContext.Site.AddCustomAction(ca);
94-
}
88+
case CustomActionScope.Web:
89+
SelectedWeb.AddCustomAction(ca);
90+
break;
91+
92+
case CustomActionScope.Site:
93+
ClientContext.Site.AddCustomAction(ca);
94+
break;
95+
96+
case CustomActionScope.All:
97+
WriteWarning("CustomActionScope All is not supported for adding CustomActions");
98+
break;
99+
}
95100
}
96101
}
97102
}

Commands/Branding/AddJavaScriptBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class AddJavaScriptBlock : SPOWebCmdlet
2727
[Alias("AddToSite")]
2828
public SwitchParameter SiteScoped;
2929

30-
[Parameter(Mandatory = false, HelpMessage = "The scope of the script to add to. Either Web or Site, defaults to Web.")]
30+
[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.")]
3131
public CustomActionScope Scope = CustomActionScope.Web;
3232

3333
protected override void ExecuteCmdlet()

Commands/Branding/AddJavaScriptLink.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,30 @@ namespace OfficeDevPnP.PowerShell.Commands
99
[Cmdlet(VerbsCommon.Add, "SPOJavaScriptLink")]
1010
[CmdletHelp("Adds a link to a JavaScript file to a web or sitecollection",
1111
Category = CmdletHelpCategory.Branding)]
12+
[CmdletExample(Code = "PS:> Add-SPOJavaScriptLink -Name jQuery -Url https://code.jquery.com/jquery.min.js -Sequence 9999 -Scope Site",
13+
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",
14+
SortOrder = 1)]
15+
[CmdletExample(Code = "PS:> Add-SPOJavaScriptLink -Name jQuery -Url https://code.jquery.com/jquery.min.js",
16+
Remarks = "Injects a reference to the latest v1 series jQuery library to all pages within the current web under the name jQuery",
17+
SortOrder = 2)]
1218
public class AddJavaScriptLink : SPOWebCmdlet
1319
{
14-
[Parameter(Mandatory = true)]
15-
public string Key = string.Empty;
20+
[Parameter(Mandatory = true, HelpMessage = "Name under which to register the JavaScriptLink")]
21+
[Alias("Key")]
22+
public string Name = string.Empty;
1623

17-
[Parameter(Mandatory = true)]
24+
[Parameter(Mandatory = true, HelpMessage = "URL to the JavaScript file to inject")]
1825
public string[] Url = null;
1926

20-
[Parameter(Mandatory = false)]
27+
[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.")]
2128
public int Sequence = 0;
2229

2330
[Parameter(Mandatory = false)]
2431
[Obsolete("Use Scope")]
2532
[Alias("AddToSite")]
2633
public SwitchParameter SiteScoped;
2734

28-
[Parameter(Mandatory = false)]
35+
[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.")]
2936
public CustomActionScope Scope = CustomActionScope.Web;
3037

3138
protected override void ExecuteCmdlet()
@@ -42,14 +49,19 @@ protected override void ExecuteCmdlet()
4249
setScope = Scope;
4350
}
4451

45-
if (setScope == CustomActionScope.Web)
52+
switch (setScope)
4653
{
47-
SelectedWeb.AddJsLink(Key, Url, Sequence);
48-
}
49-
else
50-
{
51-
var site = ClientContext.Site;
52-
site.AddJsLink(Key, Url, Sequence);
54+
case CustomActionScope.Web:
55+
SelectedWeb.AddJsLink(Name, Url, Sequence);
56+
break;
57+
58+
case CustomActionScope.Site:
59+
ClientContext.Site.AddJsLink(Name, Url, Sequence);
60+
break;
61+
62+
case CustomActionScope.All:
63+
WriteWarning("CustomActionScope All is not supported for adding JavaScriptLinks");
64+
break;
5365
}
5466
}
5567
}

0 commit comments

Comments
 (0)