microsoftgraph / microsoft-graph-explorer-v4

React/Redux version of Graph Explorer used to learn the Microsoft Graph Api
https://developer.microsoft.com/graph/graph-explorer
MIT License
213 stars 93 forks source link

Code snippit for Powershell doesn't say which graph profile to use #2357

Closed jonwbstr closed 1 year ago

jonwbstr commented 1 year ago

Using graph explorer I ran the following query

https://graph.microsoft.com/beta/deviceManagement/groupPolicyCategories?$expand=parent($select=id, displayName, isRoot),definitions($select=id, displayName, categoryPath, classType, policyType, version, hasRelatedDefinitions)&$select=id, displayName, isRoot, ingestionSource&$filter=ingestionSource eq 'builtIn'

The Code Snippet for Powershell suggested the following command:

Import-Module Microsoft.Graph.DeviceManagement.Administration

Get-MgDeviceManagementGroupPolicyCategory -ExpandProperty "parent(`$select=id,+displayName,+isRoot),definitions(`$select=id,+displayName,+categoryPath,+classType,+policyType,+version,+hasRelatedDefinitions)" -Property "id,+displayName,+isRoot,+ingestionSource" -Filter "ingestionSource+eq+'builtIn'" 

The command Get-MgDeviceManagementGroupPolicyCategory is currently available in the 'beta' profile so the correct code is

Import-Module Microsoft.Graph.DeviceManagement.Administration
Select-MgProfile -name beta

Get-MgDeviceManagementGroupPolicyCategory -ExpandProperty "parent(`$select=id,+displayName,+isRoot),definitions(`$select=id,+displayName,+categoryPath,+classType,+policyType,+version,+hasRelatedDefinitions)" -Property "id,+displayName,+isRoot,+ingestionSource" -Filter "ingestionSource+eq+'builtIn'" 

The javascript example does note which version of grah to use.

peombwa commented 1 year ago

Thanks for following up on this.

There is a link in the comments that shows customer how to load the right profile version using Select-MgProfile - https://aka.ms/pshellsdkdocs. We don't include Select-MgProfile in the snippets as it can be called at any point in a script, ideally at the beginning of a script together with Connect-MgGraph.

We've also dropped support for profiles in v2.x, so Select-MgProfile will no longer be needed once we GA v2.x in a few weeks - msgraph-sdk-powershell/upgrade-to-v2.md at features/2.0 · microsoftgraph/msgraph-sdk-powershell (github.com).

jonwbstr commented 1 year ago

Thanks for the update, looking forward to 2.x!