Skip to content

Commit

Permalink
Merge pull request #1935 from milanholemans/getplannerplan-planid
Browse files Browse the repository at this point in the history
Introduce plan ID parameter for `Get-PnPPlannerPlan`
  • Loading branch information
KoenZomers authored Jun 9, 2022
2 parents 34f070d + d56c221 commit d387980
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `-IncludeContentType` parameter, which if specified will retrieve content type information of the list items. [#1921](https://github.com/pnp/powershell/pull/1921)
- Added optional `-ValidateConnection` to `Connect-PnPOnline` which will check if the site you are connecting to exists and if not, will throw an exception [#1924](https://github.com/pnp/powershell/pull/1924)
- Added `AllowTenantMoveWithDataMigration` to `Get-PnPPlannerConfiguration` and `Set-PnPPlannerConfiguration` [#1934](https://github.com/pnp/powershell/pull/1934)
- Added the ability to retrieve a Planner plan by only its Id using `Get-PnPPlannerPlan -Identity <id>` [#1935](https://github.com/pnp/powershell/pull/1935)
- Added `Add-PnPListItemAttachment` cmdlet to provide ability to upload a file as an attachment to a SharePoint list item. [#1932](https://github.com/pnp/powershell/pull/1932)
- Added `Remove-PnPListItemAttachment` cmdlet to provide ability to delete a list item attachment. [#1932](https://github.com/pnp/powershell/pull/1932)
- Added `Get-PnPListItemAttachment` cmdlet to download the attachments from a list item. [#1932](https://github.com/pnp/powershell/pull/1932)
Expand Down
33 changes: 31 additions & 2 deletions documentation/Get-PnPPlannerPlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ Returns all or a specific Planner plan for a Microsoft 365 Group.

## SYNTAX

### By Group
```powershell
Get-PnPPlannerPlan -Group <PlannerGroupPipeBind> [-Identity <PlannerPlanPipeBind>] [-ResolveIdentities]
[<CommonParameters>]
```

### By Plan Id
```powershell
Get-PnPPlannerPlan -Id <String> [-ResolveIdentities]
[<CommonParameters>]
```

## DESCRIPTION
This cmdlet returns all or a specific Planner plan for a Microsoft 365 Group.

Expand All @@ -44,14 +51,21 @@ Get-PnPPlannerPlan -Group "Marketing" -Identity "Conference Plan"

Returns the specified plan for the Marketing group.

### Example 3
```powershell
Get-PnPPlannerPlan -Id "gndWOTSK60GfPQfiDDj43JgACDCb" -ResolveIdentities
```

Rerturns the plan with specified ID with resolved identities.

## PARAMETERS

### -Group
Specify the group containing the plans

```yaml
Type: PlannerGroupPipeBind
Parameter Sets: (All)
Parameter Sets: By Group
Aliases:

Required: True
Expand All @@ -66,7 +80,7 @@ If specified the plan with this ID or Name will be returned.
```yaml
Type: PlannerPlanPipeBind
Parameter Sets: (All)
Parameter Sets: By Group
Aliases:

Required: False
Expand All @@ -76,6 +90,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Id
If specified the plan with this ID will be returned.
```yaml
Type: String
Parameter Sets: By Plan Id
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -ResolveIdentities
Show user display names instead of user IDs.
Expand Down
32 changes: 22 additions & 10 deletions src/Commands/Planner/GetPlannerPlan.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,54 @@
using System.Management.Automation;
using Microsoft.Graph;
using PnP.PowerShell.Commands.Attributes;
using PnP.PowerShell.Commands.Base;
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Utilities;
using System.Management.Automation;

namespace PnP.PowerShell.Commands.Planner
{
[Cmdlet(VerbsCommon.Get, "PnPPlannerPlan")]
[RequiredMinimalApiPermissions("Group.Read.All")]
public class GetPlannerPlan : PnPGraphCmdlet
{
[Parameter(Mandatory = true)]
private const string ParameterName_BYGROUP = "By Group";
private const string ParameterName_BYPLANID = "By Plan Id";

[Parameter(Mandatory = true, HelpMessage = "Specify the group id of group owning the plan.", ParameterSetName = ParameterName_BYGROUP)]
public PlannerGroupPipeBind Group;

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, HelpMessage = "Specify the name of the plan.", ParameterSetName = ParameterName_BYGROUP)]
public PlannerPlanPipeBind Identity;

[Parameter(Mandatory = true, HelpMessage = "Specify the ID of the plan.", ParameterSetName = ParameterName_BYPLANID)]
public string Id;

[Parameter(Mandatory = false)]
public SwitchParameter ResolveIdentities;

protected override void ExecuteCmdlet()
{
var groupId = Group.GetGroupId(HttpClient, AccessToken);
if (groupId != null)
if (ParameterSetName == ParameterName_BYGROUP)
{
if (ParameterSpecified(nameof(Identity)))
var groupId = Group.GetGroupId(HttpClient, AccessToken);
if (groupId != null)
{
WriteObject(Identity.GetPlanAsync(HttpClient, AccessToken, groupId, ResolveIdentities).GetAwaiter().GetResult());
if (ParameterSpecified(nameof(Identity)))
{
WriteObject(Identity.GetPlanAsync(HttpClient, AccessToken, groupId, ResolveIdentities).GetAwaiter().GetResult());
}
else
{
WriteObject(PlannerUtility.GetPlansAsync(HttpClient, AccessToken, groupId, ResolveIdentities).GetAwaiter().GetResult(), true);
}
}
else
{
WriteObject(PlannerUtility.GetPlansAsync(HttpClient, AccessToken, groupId, ResolveIdentities).GetAwaiter().GetResult(), true);
throw new PSArgumentException("Group not found");
}
}
else
{
throw new PSArgumentException("Group not found");
WriteObject(PlannerUtility.GetPlanAsync(HttpClient, AccessToken, Id, ResolveIdentities).GetAwaiter().GetResult());
}
}
}
Expand Down

0 comments on commit d387980

Please sign in to comment.