|
1 |
| -using System.Management.Automation; |
2 |
| -using Microsoft.Graph; |
3 | 1 | using PnP.PowerShell.Commands.Attributes;
|
4 | 2 | using PnP.PowerShell.Commands.Base;
|
5 | 3 | using PnP.PowerShell.Commands.Base.PipeBinds;
|
6 | 4 | using PnP.PowerShell.Commands.Utilities;
|
| 5 | +using System.Management.Automation; |
7 | 6 |
|
8 | 7 | namespace PnP.PowerShell.Commands.Planner
|
9 | 8 | {
|
10 | 9 | [Cmdlet(VerbsCommon.Get, "PnPPlannerPlan")]
|
11 | 10 | [RequiredMinimalApiPermissions("Group.Read.All")]
|
12 | 11 | public class GetPlannerPlan : PnPGraphCmdlet
|
13 | 12 | {
|
14 |
| - [Parameter(Mandatory = true)] |
| 13 | + private const string ParameterName_BYGROUP = "By Group"; |
| 14 | + private const string ParameterName_BYPLANID = "By Plan Id"; |
| 15 | + |
| 16 | + [Parameter(Mandatory = true, HelpMessage = "Specify the group id of group owning the plan.", ParameterSetName = ParameterName_BYGROUP)] |
15 | 17 | public PlannerGroupPipeBind Group;
|
16 | 18 |
|
17 |
| - [Parameter(Mandatory = false)] |
| 19 | + [Parameter(Mandatory = false, HelpMessage = "Specify the name of the plan.", ParameterSetName = ParameterName_BYGROUP)] |
18 | 20 | public PlannerPlanPipeBind Identity;
|
19 | 21 |
|
| 22 | + [Parameter(Mandatory = true, HelpMessage = "Specify the ID of the plan.", ParameterSetName = ParameterName_BYPLANID)] |
| 23 | + public string Id; |
20 | 24 |
|
21 | 25 | [Parameter(Mandatory = false)]
|
22 | 26 | public SwitchParameter ResolveIdentities;
|
| 27 | + |
23 | 28 | protected override void ExecuteCmdlet()
|
24 | 29 | {
|
25 |
| - var groupId = Group.GetGroupId(HttpClient, AccessToken); |
26 |
| - if (groupId != null) |
| 30 | + if (ParameterSetName == ParameterName_BYGROUP) |
27 | 31 | {
|
28 |
| - if (ParameterSpecified(nameof(Identity))) |
| 32 | + var groupId = Group.GetGroupId(HttpClient, AccessToken); |
| 33 | + if (groupId != null) |
29 | 34 | {
|
30 |
| - WriteObject(Identity.GetPlanAsync(HttpClient, AccessToken, groupId, ResolveIdentities).GetAwaiter().GetResult()); |
| 35 | + if (ParameterSpecified(nameof(Identity))) |
| 36 | + { |
| 37 | + WriteObject(Identity.GetPlanAsync(HttpClient, AccessToken, groupId, ResolveIdentities).GetAwaiter().GetResult()); |
| 38 | + } |
| 39 | + else |
| 40 | + { |
| 41 | + WriteObject(PlannerUtility.GetPlansAsync(HttpClient, AccessToken, groupId, ResolveIdentities).GetAwaiter().GetResult(), true); |
| 42 | + } |
31 | 43 | }
|
32 | 44 | else
|
33 | 45 | {
|
34 |
| - WriteObject(PlannerUtility.GetPlansAsync(HttpClient, AccessToken, groupId, ResolveIdentities).GetAwaiter().GetResult(), true); |
| 46 | + throw new PSArgumentException("Group not found"); |
35 | 47 | }
|
36 | 48 | }
|
37 | 49 | else
|
38 | 50 | {
|
39 |
| - throw new PSArgumentException("Group not found"); |
| 51 | + WriteObject(PlannerUtility.GetPlanAsync(HttpClient, AccessToken, Id, ResolveIdentities).GetAwaiter().GetResult()); |
40 | 52 | }
|
41 | 53 | }
|
42 | 54 | }
|
|
0 commit comments