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

Commit 54f90cd

Browse files
Merge pull request #783 from SharePoint/dev
March 2017 Release
2 parents fb01372 + 4645086 commit 54f90cd

File tree

71 files changed

+2078
-198
lines changed

Some content is hidden

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

71 files changed

+2078
-198
lines changed

Commands/Base/ConnectOnline.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Linq;
88
using Microsoft.SharePoint.Client;
99
using OfficeDevPnP.Core;
10+
using SharePointPnP.PowerShell.Commands.Provider;
1011
using File = System.IO.File;
1112
#if !ONPREMISES
1213
using Microsoft.SharePoint.Client.CompliancePolicy;
@@ -201,7 +202,7 @@ protected override void ProcessRecord()
201202

202203
if (CreateDrive && SPOnlineConnection.CurrentConnection.Context != null)
203204
{
204-
var provider = SessionState.Provider.GetAll().FirstOrDefault(p => p.Name.Equals("SPO", StringComparison.InvariantCultureIgnoreCase));
205+
var provider = SessionState.Provider.GetAll().FirstOrDefault(p => p.Name.Equals(SPOProvider.PSProviderName, StringComparison.InvariantCultureIgnoreCase));
205206
if (provider != null)
206207
{
207208
if (provider.Drives.Any(d => d.Name.Equals(DriveName, StringComparison.InvariantCultureIgnoreCase)))
Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,61 @@
11
using Microsoft.Identity.Client;
22
using SharePointPnP.PowerShell.CmdletHelpAttributes;
33
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
64
using System.Management.Automation;
7-
using System.Text;
8-
using System.Threading.Tasks;
5+
using AuthenticationResult = Microsoft.Identity.Client.AuthenticationResult;
6+
using ClientCredential = Microsoft.Identity.Client.ClientCredential;
97

108
namespace SharePointPnP.PowerShell.Commands.Base
119
{
12-
[Cmdlet("Connect", "PnPMicrosoftGraph")]
10+
[Cmdlet("Connect", "PnPMicrosoftGraph", DefaultParameterSetName = "Scope")]
1311
[CmdletHelp("Uses the Microsoft Authentication Library (Preview) to connect to Azure AD and to get an OAuth 2.0 Access Token to consume the Microsoft Graph API",
1412
Category = CmdletHelpCategory.Graph)]
1513
[CmdletExample(
1614
Code = "PS:> Connect-PnPMicrosoftGraph -Scopes $arrayOfScopes",
1715
Remarks = "Connects to Azure AD and gets and OAuth 2.0 Access Token to consume the Microsoft Graph API including the declared permission scopes. The available permission scopes are defined at the following URL: https://graph.microsoft.io/en-us/docs/authorization/permission_scopes",
1816
SortOrder = 1)]
17+
[CmdletExample(
18+
Code = "PS:> Connect-PnPMicrosoftGraph -AppId '<id>' -AppSecret '<secrect>' -AADDomain 'contoso.onmicrosoft.com'",
19+
Remarks = "Connects to the Microsoft Graph API using application permissions via an app's declared permission scopes. See https://github.com/SharePoint/PnP-PowerShell/tree/master/Samples/Graph.ConnectUsingAppPermissions for a sample on how to get started.",
20+
SortOrder = 2)]
1921
public class ConnectPnPMicrosoftGraph : PSCmdlet
2022
{
2123
private const string MSALPnPPowerShellClientId = "bb0c5778-9d5c-41ea-a4a8-8cd417b3ab71";
24+
private const string RedirectUri = "urn:ietf:wg:oauth:2.0:oob";
25+
private static readonly Uri AADLogin = new Uri("https://login.microsoftonline.com/");
26+
private static readonly string[] DefaultScope = { "https://graph.microsoft.com/.default" };
27+
28+
[Parameter(Mandatory = true, HelpMessage = "The array of permission scopes for the Microsoft Graph API.", ParameterSetName = "Scope")]
29+
public string[] Scopes;
30+
31+
[Parameter(Mandatory = true, HelpMessage = "The client id of the app which gives you access to the Microsoft Graph API.", ParameterSetName = "AAD")]
32+
public string AppId;
2233

23-
[Parameter(Mandatory = true, HelpMessage = "The array of permission scopes for the Microsoft Graph API.")]
24-
public String[] Scopes;
34+
[Parameter(Mandatory = true, HelpMessage = "The app key of the app which gives you access to the Microsoft Graph API.", ParameterSetName = "AAD")]
35+
public string AppSecret;
36+
37+
[Parameter(Mandatory = true, HelpMessage = "The AAD where the O365 app is registred. Eg.: contoso.com, or contoso.onmicrosoft.com.", ParameterSetName = "AAD")]
38+
public string AADDomain;
2539

2640
protected override void ProcessRecord()
2741
{
28-
PublicClientApplication clientApplication =
29-
new PublicClientApplication(MSALPnPPowerShellClientId);
30-
31-
// Acquire an access token for the given scope
32-
var authenticationResult = clientApplication.AcquireTokenAsync(Scopes).GetAwaiter().GetResult();
42+
AuthenticationResult authenticationResult;
43+
if (Scopes != null)
44+
{
45+
var clientApplication = new PublicClientApplication(MSALPnPPowerShellClientId);
46+
// Acquire an access token for the given scope
47+
authenticationResult = clientApplication.AcquireTokenAsync(Scopes).GetAwaiter().GetResult();
48+
}
49+
else
50+
{
51+
var appCredentials = new ClientCredential(AppSecret);
52+
var authority = new Uri(AADLogin, AADDomain).AbsoluteUri;
53+
var clientApplication = new ConfidentialClientApplication(authority, AppId, RedirectUri, appCredentials, null);
54+
authenticationResult = clientApplication.AcquireTokenForClient(DefaultScope, null).GetAwaiter().GetResult();
55+
}
3356

3457
// Get back the Access Token and the Refresh Token
3558
PnPAzureADConnection.AuthenticationResult = authenticationResult;
3659
}
3760
}
38-
}
61+
}

Commands/Base/DisconnectSPOnline.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ protected override void ProcessRecord()
2222
if (!DisconnectCurrentService())
2323
throw new InvalidOperationException(Properties.Resources.NoConnectionToDisconnect);
2424

25-
var provider = SessionState.Provider.GetAll().FirstOrDefault(p => p.Name.Equals("SPO", StringComparison.InvariantCultureIgnoreCase));
25+
var provider = SessionState.Provider.GetAll().FirstOrDefault(p => p.Name.Equals(SPOProvider.PSProviderName, StringComparison.InvariantCultureIgnoreCase));
2626
if (provider != null)
2727
{
28-
var drives = provider.Drives.Where(d => d.Provider.Module.ImplementingAssembly.FullName == Assembly.GetExecutingAssembly().FullName);
28+
//ImplementingAssembly was introduced in Windows PowerShell 5.0.
29+
var drives = Host.Version.Major >= 5 ? provider.Drives.Where(d => d.Provider.Module.ImplementingAssembly.FullName == Assembly.GetExecutingAssembly().FullName) : provider.Drives;
2930
foreach (var drive in drives)
3031
{
31-
var spoDrive = drive as SPODriveInfo;
32-
spoDrive.ClearState();
3332
SessionState.Drive.Remove(drive.Name, true, "Global");
3433
}
3534
}

Commands/Extensions/ClientObjectExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Linq;
44
using System.Linq.Expressions;
5+
using System.Reflection;
56

67
namespace SharePointPnP.PowerShell.Commands.Extensions
78
{
@@ -51,5 +52,12 @@ private static Expression<Func<T, object>> GetClientObjectExpression<T>(T client
5152

5253
return exp;
5354
}
55+
56+
internal static void ClearObjectData(this ClientObject clientObject)
57+
{
58+
var info_ClientObject_ObjectData = typeof(ClientObject).GetProperty("ObjectData", BindingFlags.NonPublic | BindingFlags.Instance);
59+
var objectData = (ClientObjectData)info_ClientObject_ObjectData.GetValue(clientObject, new object[0]);
60+
objectData.MethodReturnObjects.Clear();
61+
}
5462
}
5563
}

Commands/Files/CopyFile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ public class CopyFile : PnPWebCmdlet
8989

9090
protected override void ExecuteCmdlet()
9191
{
92+
#pragma warning disable CS0618 // Type or member is obsolete
9293
SourceUrl = SourceUrl ?? ServerRelativeUrl;
94+
#pragma warning restore CS0618 // Type or member is obsolete
9395
var webServerRelativeUrl = SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl);
9496

9597
if (!SourceUrl.StartsWith("/"))

Commands/Graph/SetUnifiedGroup.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
using OfficeDevPnP.Core.Entities;
22
using OfficeDevPnP.Core.Framework.Graph;
3-
using OfficeDevPnP.Core.Utilities;
43
using SharePointPnP.PowerShell.CmdletHelpAttributes;
54
using SharePointPnP.PowerShell.Commands.Base;
65
using SharePointPnP.PowerShell.Commands.Base.PipeBinds;
76
using System;
8-
using System.Collections.Generic;
97
using System.IO;
10-
using System.Linq;
118
using System.Management.Automation;
12-
using System.Text;
13-
using System.Threading.Tasks;
149

1510
namespace SharePointPnP.PowerShell.Commands.Graph
1611
{
@@ -29,6 +24,14 @@ namespace SharePointPnP.PowerShell.Commands.Graph
2924
Code = @"PS:> Set-PnPUnifiedGroup -Identity $group -GroupLogoPath "".\MyLogo.png""",
3025
Remarks = "Sets a specific Office 365 Group logo.",
3126
SortOrder = 3)]
27+
[CmdletExample(
28+
Code = @"PS:> Set-PnPUnifiedGroup -Identity $group -IsPrivate:$false",
29+
Remarks = "Sets a group to be Public if previously Private.",
30+
SortOrder = 4)]
31+
[CmdletExample(
32+
Code = @"PS:> Set-PnPUnifiedGroup -Identity $group -Owners [email protected]",
33+
Remarks = "Adds [email protected] as an additional owner to the group.",
34+
SortOrder = 5)]
3235
public class SetUnifiedGroup : PnPGraphCmdlet
3336
{
3437
[Parameter(Mandatory = true, HelpMessage = "The Identity of the Office 365 Group.", ValueFromPipeline = true)]
@@ -40,6 +43,15 @@ public class SetUnifiedGroup : PnPGraphCmdlet
4043
[Parameter(Mandatory = false, HelpMessage = "The Description of the group to set.")]
4144
public string Description;
4245

46+
[Parameter(Mandatory = false, HelpMessage = "The array UPN values of owners to add to the group.")]
47+
public String[] Owners;
48+
49+
[Parameter(Mandatory = false, HelpMessage = "The array UPN values of members to add to the group.")]
50+
public String[] Members;
51+
52+
[Parameter(Mandatory = false, HelpMessage = "Makes the group private when selected.")]
53+
public SwitchParameter IsPrivate;
54+
4355
[Parameter(Mandatory = false, HelpMessage = "The path to the logo file of to set.")]
4456
public string GroupLogoPath;
4557

@@ -72,8 +84,9 @@ protected override void ExecuteCmdlet()
7284
}
7385
groupLogoStream = new FileStream(GroupLogoPath, FileMode.Open, FileAccess.Read);
7486
}
87+
7588
UnifiedGroupsUtility.UpdateUnifiedGroup(group.GroupId, AccessToken, displayName: DisplayName,
76-
description: Description, groupLogo: groupLogoStream);
89+
description: Description, owners: Owners, members: Members, groupLogo: groupLogoStream, isPrivate: IsPrivate);
7790
}
7891
}
7992
}

Commands/Lists/AddListItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class AddListItem : PnPWebCmdlet
5757
"\n\nMulti value lookup (id of lookup values as array 1): -Values @{\"MultiLookupField\" = \"1\",\"2\"}" +
5858
"\n\nMulti value lookup (id of lookup values as array 2): -Values @{\"MultiLookupField\" = 1,2}" +
5959
"\n\nMulti value lookup (id of lookup values as string): -Values @{\"MultiLookupField\" = \"1,2\"}" +
60-
"\n\nYes/No: -Values @{\"YesNo\" = \"No\"}" +
60+
"\n\nYes/No: -Values @{\"YesNo\" = $false}" +
6161
"\n\nPerson/Group (id of user/group in Site User Info List or email of the user, seperate multiple values with a comma): -Values @{\"Person\" = \"[email protected]\",\"21\"}" +
6262
"\n\nManaged Metadata (single value with path to term): -Values @{\"MetadataField\" = \"CORPORATE|DEPARTMENTS|FINANCE\"}" +
6363
"\n\nManaged Metadata (single value with id of term): -Values @{\"MetadataField\" = \"fe40a95b-2144-4fa2-b82a-0b3d0299d818\"} with Id of term" +

Commands/Lists/SetDefaultColumnValues.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ namespace SharePointPnP.PowerShell.Commands.Lists
2929
Code = "PS:> Set-PnPDefaultColumnValues -List Documents -Field MyTextField -Value \"DefaultValue\"",
3030
SortOrder = 3,
3131
Remarks = "Sets a default value for the MyTextField text field on a library to a value of \"DefaultValue\"")]
32+
[CmdletExample(
33+
Code = "PS:> Set-PnPDefaultColumnValues -List Documents -Field MyPeopleField -Value \"1;#Foo Bar\"",
34+
SortOrder = 4,
35+
Remarks = "Sets a default value for the MyPeopleField people field on a library to a value of \"Foo Bar\" using the id from the user information list.")]
36+
[CmdletExample(
37+
Code = "PS:> $user = New-PnPUser -LoginName [email protected]\nPS:> Set-PnPDefaultColumnValues -List Documents -Field MyPeopleField -Value \"$($user.Id);#$($user.LoginName)\"",
38+
SortOrder = 5,
39+
Remarks = "Sets a default value for the MyPeopleField people field on a library to a value of \"Foo Bar\" using the id from the user information list.")]
40+
[CmdletExample(
41+
Code = "PS:> $user1 = New-PnPUser -LoginName [email protected]\nPS:> $user2 = New-PnPUser -LoginName [email protected]\nPS:> Set-PnPDefaultColumnValues -List Documents -Field MyMultiPeopleField -Value \"$($user1.Id);#$($user1.LoginName)\",\"$($user2.Id);#$($user2.LoginName)\"",
42+
SortOrder = 6,
43+
Remarks = "Sets a default value for the MyMultiPeopleField people field on a library to a value of \"User 1\" and \"User 2\" using the id from the user information list.")]
3244
public class SetDefaultColumnValues : PnPWebCmdlet
3345
{
3446
[Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "The ID, Name or Url of the list.")]
@@ -37,7 +49,7 @@ public class SetDefaultColumnValues : PnPWebCmdlet
3749
[Parameter(Mandatory = true, HelpMessage = "The internal name, id or a reference to a field")]
3850
public FieldPipeBind Field;
3951

40-
[Parameter(Mandatory = true, HelpMessage = "A list of values. In case of a text field the values will be concatenated, separated by a semi-colon. In case of a taxonomy field multiple values will added")]
52+
[Parameter(Mandatory = true, HelpMessage = "A list of values. In case of a text field the values will be concatenated, separated by a semi-colon. In case of a taxonomy field multiple values will added. In case of people field multiple values will be added.")]
4153
public string[] Value;
4254

4355
[Parameter(Mandatory = false, HelpMessage = "A library relative folder path, if not specified it will set the default column values on the root folder of the library ('/')")]
@@ -80,7 +92,7 @@ protected override void ExecuteCmdlet()
8092
if (field != null)
8193
{
8294
IDefaultColumnValue defaultColumnValue = null;
83-
if (field.TypeAsString == "Text" || field.TypeAsString == "Choice" || field.TypeAsString == "MultiChoice")
95+
if (field.TypeAsString == "Text" || field.TypeAsString == "Choice" || field.TypeAsString == "MultiChoice" || field.TypeAsString == "User")
8496
{
8597
var values = string.Join(";", Value);
8698
defaultColumnValue = new DefaultColumnTextValue()
@@ -90,6 +102,16 @@ protected override void ExecuteCmdlet()
90102
Text = values
91103
};
92104
}
105+
else if (field.TypeAsString == "UserMulti")
106+
{
107+
var values = string.Join(";#", Value);
108+
defaultColumnValue = new DefaultColumnTextValue()
109+
{
110+
FieldInternalName = field.InternalName,
111+
FolderRelativePath = Folder,
112+
Text = values
113+
};
114+
}
93115
else
94116
{
95117
List<Term> terms = new List<Term>();
@@ -101,7 +123,7 @@ protected override void ExecuteCmdlet()
101123
{
102124
var taxSession = ClientContext.Site.GetTaxonomySession();
103125
term = taxSession.GetTerm(termGuid);
104-
ClientContext.ExecuteQueryRetry();
126+
ClientContext.ExecuteQueryRetry();
105127
}
106128
else
107129
{

Commands/Lists/SetListItem.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class SetListItem : PnPWebCmdlet
5454
"\n\nMulti value lookup (id of lookup values as array 1): -Values @{\"MultiLookupField\" = \"1\",\"2\"}" +
5555
"\n\nMulti value lookup (id of lookup values as array 2): -Values @{\"MultiLookupField\" = 1,2}" +
5656
"\n\nMulti value lookup (id of lookup values as string): -Values @{\"MultiLookupField\" = \"1,2\"}" +
57-
"\n\nYes/No: -Values @{\"YesNoField\" = \"No\"}" +
57+
"\n\nYes/No: -Values @{\"YesNoField\" = $false}" +
5858
"\n\nPerson/Group (id of user/group in Site User Info List or email of the user, seperate multiple values with a comma): -Values @{\"PersonField\" = \"[email protected]\",\"21\"}" +
5959
"\n\nManaged Metadata (single value with path to term): -Values @{\"MetadataField\" = \"CORPORATE|DEPARTMENTS|FINANCE\"}" +
6060
"\n\nManaged Metadata (single value with id of term): -Values @{\"MetadataField\" = \"fe40a95b-2144-4fa2-b82a-0b3d0299d818\"} with Id of term" +
@@ -131,10 +131,10 @@ protected override void ExecuteCmdlet()
131131
var value = values[key];
132132
if (value.GetType().IsArray)
133133
{
134-
foreach (var arrayItem in value as object[])
134+
foreach (var arrayItem in (value as IEnumerable))
135135
{
136136
int userId;
137-
if (!int.TryParse(arrayItem as string, out userId))
137+
if (!int.TryParse(arrayItem.ToString(), out userId))
138138
{
139139
var user = SelectedWeb.EnsureUser(arrayItem as string);
140140
ClientContext.Load(user);

Commands/ModuleFiles/SharePointPnP.PowerShell.2013.Commands.Format.ps1xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@
559559
<TypeName>Microsoft.SharePoint.Client.Folder</TypeName>
560560
</ViewSelectedBy>
561561
<GroupBy>
562-
<ScriptBlock>$_.PSParentPath.Replace("SharePointPnPPowerShellOnline\SPO::", "")</ScriptBlock>
562+
<ScriptBlock>$_.PSParentPath.Replace("SharePointPnPPowerShell2013\SharePoint::", "")</ScriptBlock>
563563
<Label>Folder</Label>
564564
</GroupBy>
565565
<TableControl>

Commands/ModuleFiles/SharePointPnP.PowerShell.2016.Commands.Format.ps1xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@
559559
<TypeName>Microsoft.SharePoint.Client.Folder</TypeName>
560560
</ViewSelectedBy>
561561
<GroupBy>
562-
<ScriptBlock>$_.PSParentPath.Replace("SharePointPnPPowerShellOnline\SPO::", "")</ScriptBlock>
562+
<ScriptBlock>$_.PSParentPath.Replace("SharePointPnPPowerShell2016\SharePoint::", "")</ScriptBlock>
563563
<Label>Folder</Label>
564564
</GroupBy>
565565
<TableControl>

Commands/ModuleFiles/SharePointPnP.PowerShell.Online.Commands.Format.ps1xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@
559559
<TypeName>Microsoft.SharePoint.Client.Folder</TypeName>
560560
</ViewSelectedBy>
561561
<GroupBy>
562-
<ScriptBlock>$_.PSParentPath.Replace("SharePointPnPPowerShellOnline\SPO::", "")</ScriptBlock>
562+
<ScriptBlock>$_.PSParentPath.Replace("SharePointPnPPowerShellOnline\SharePoint::", "")</ScriptBlock>
563563
<Label>Folder</Label>
564564
</GroupBy>
565565
<TableControl>

Commands/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@
4444
// You can specify all the values or you can default the Build and Revision Numbers
4545
// by using the '*' as shown below:
4646
// [assembly: AssemblyVersion("1.0.*")]
47-
[assembly: AssemblyVersion("2.12.1702.0")]
48-
[assembly: AssemblyFileVersion("2.12.1702.0")]
47+
[assembly: AssemblyVersion("2.13.1703.0")]
48+
[assembly: AssemblyFileVersion("2.13.1703.0")]
4949
[assembly: InternalsVisibleTo("SharePointPnP.PowerShell.Tests")]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Management.Automation;
2+
3+
namespace SharePointPnP.PowerShell.Commands.Provider.Parameters
4+
{
5+
public class SPOChildItemsParameters
6+
{
7+
[Parameter(HelpMessage = "Limit items collected when using list query")]
8+
public Limits Limit { get; set; }
9+
10+
public enum Limits
11+
{
12+
Default,
13+
All = -1
14+
}
15+
}
16+
}

Commands/Provider/SPOContentParameters.cs renamed to Commands/Provider/Parameters/SPOContentParameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Management.Automation;
22

3-
namespace SharePointPnP.PowerShell.Commands.Provider
3+
namespace SharePointPnP.PowerShell.Commands.Provider.Parameters
44
{
55
public class SPOContentParameters
66
{

0 commit comments

Comments
 (0)