pnp / powershell

PnP PowerShell
https://pnp.github.io/powershell
MIT License
684 stars 351 forks source link

[BUG] Cannot use Get-PnPProperty to get properties of Teams #4563

Closed MikeGitUser closed 5 days ago

MikeGitUser commented 5 days ago

Hi Team,

Unable to get the Apps property populated in a Team object. Please see the code example below.

My Azure app has Ms Graph App level scope "Group.Read.All" consented.

Connect-PnPOnline -Url "https://zzzzzzz.sharepoint.com" -ClientId "zzzzzzz-zzzzzz-zzzzzz-zzzzz-2be1961499f8" -Tenant "zzzzz.onmicrosoft.com" -Thumbprint "zzzzzzzzzzzzzzzzzzzzzzz584878ACA5A8AF970"
$team = Get-PnPTeamsTeam -Identity "MyTeamName"
Get-PnPProperty -ClientObject $team -Property Apps   ### (note: I've tried $team[0] also incase $team is a collection, but same result)

The call to Get-PnPTeamsTeam is successful and returns the Team details in $team, however "Get-PnPProperty" returns the following error:

Get-PnPProperty : Cannot bind parameter 'ClientObject'. Cannot convert the "PnP.PowerShell.Commands.Model.Teams.Team" value of type "PnP.PowerShell.Commands.Model.Teams.Team" to type "Microsoft.SharePoint.Client.ClientObject". At line:2 char:31

  • Get-PnPProperty -ClientObject $team -Property Apps
    • CategoryInfo : InvalidArgument: (:) [Get-PnPProperty], ParameterBindingException
    • FullyQualifiedErrorId : CannotConvertArgumentNoMessage,PnP.PowerShell.Commands.Base.EnsureProperty

I've tried this in both PowerShell 5 and 7 and the following PnP releases and get the same error.

PowerShell 5
>  Get-Command Connect-PnPOnline

CommandType     Name                                               Version    Source                                                                                                                                                                     
-----------     ----                                               -------    ------                                                                                                                                                                     
Cmdlet          Connect-PnPOnline                                  1.12.0     PnP.PowerShell  

PowerShell 7
> Get-Command Connect-PnPOnline

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Connect-PnPOnline                                  2.12.0     PnP.PowerShell

Please let me know if I'm doing something wrong.

Thanks!!

gautamdsheth commented 5 days ago

Hey @MikeGitUser , this is by design, not a bug. Get-PnPProperty only works with SharePoint client objects like Web, Lists etc. It is not designed to work with Graph objects.

You can use Invoke-PnPGraphMethod to request additional teams properties.