powershell icon indicating copy to clipboard operation
powershell copied to clipboard

[FEATURE] Invoke-PnPGraphMethod -AdditionalHeaders does not accept a hashtable

Open joshtransient opened this issue 1 year ago • 1 comments

Reporting an Issue or Missing Feature

I'm considering this an issue (not a feature request) since I'd expect others to also file this as a bug. I'm all for using generics for type safety, but...come on. I shouldn't have to cast a whole new dictionary on a separate line just to use this argument.

Expected behavior

The -AdditionalHeaders argument of Invoke-PnPGraphMethod should accept a hashtable the sake of simplicity and readability.

Actual behavior

When using a hashtable in the -AdditionalHeaders argument of Invoke-PnPGraphMethod, I receive the error message:

Cannot bind parameter 'AdditionalHeaders'. Cannot convert the "System.Collections.Hashtable" value of type "System.Collections.Hashtable" to type "System.Collections.Generic.IDictionary`2[System.String,System.String]".

The workaround is:

$dict = [System.Collections.Generic.Dictionary[string,string]]::new()
$dict.Add('header','value')
$dict.Add('header2','value2')
Invoke-PnPGraphMethod ... -AdditionalHeaders $dict

Steps to reproduce behavior

Sample command (Connected to PnP with -Interactive or an app registration with User.Read.All):

Invoke-PnPGraphMethod -Method Get -Url 'https://graph.microsoft.com/v1.0/users?$select=displayName&$filter=assignedLicenses/$count ne 0&$count=true' -AdditionalHeaders @{ ConsistencyLevel = 'eventual' }

What is the version of the Cmdlet module you are running?

2.4.0

Which operating system/environment are you running PnP PowerShell on?

  • [x] Windows
  • [ ] Linux
  • [ ] MacOS
  • [ ] Azure Cloud Shell
  • [ ] Azure Functions
  • [ ] Other : please specify

joshtransient avatar Jun 21 '24 17:06 joshtransient

@joshtransient - appreciate your feedback. We will update this in v3 to a hashtable.

It is not a bug, will consider this as enhancement though. Can't change it in current versions, 2.x, as it will be a breaking change.

gautamdsheth avatar Jun 26 '24 18:06 gautamdsheth

@joshtransient - this has been added in the latest nightly release. Turns out, it didn't require a breaking change for this.

Thanks for raising this feature request.

gautamdsheth avatar Sep 07 '24 14:09 gautamdsheth