Introduction
In the previous article (link here) we covered the basics of connecting to Microsoft Graph PowerShell as well as some of the requirements that go along with the connection. This week we will review how to find cmdlet for Graph to help start to break down what is available in this module as well as to hopefully help guide us to cmdlets needed to perform tasks in Graph. Keep in mind that there are a lot of cmdlets
Get-Command | Where Source -Like Microsoft.Graph.*
Above is a small sampling of the Graph cmdlet. Notice the Sources on the righthand side as well. The total number of cmdlets, as of the writing of this blog, is over 7000:
Now let’s breakdown the cmdlets by module.
SubModules
So, we have a way to list the cmdlets and we know that there are at least a few submodules, what submodules do we have to work with?
(Get-Command | Where Source -Like Microsoft.Graph.*).Source | Sort -Unique
From our above screenshot we see there are 38 submodules present in the Microsoft Graph PowerShell SDK and we can further break things down by examining how many cmdlets there are per module:
$Submodules = (Get-Command | Where Source -Like Microsoft.Graph.*).Source | Sort -Unique Foreach ($Submodule in $Submodules) { Write-host "Cmdlets available for $Submodule - " -ForegroundColor White -NoNewLine $Number = (Get-Command | Where {$_.Source -eq $Submodule}).Count Write-host "$Number" -ForegroundColor Green }
Find cmdlets by Submodule
One method to finding cmdlets is to review cmdlets that are in each submodule of the Graph PowerShell module and might help bubble a cmdlet that is useful to a scenario or work process you have.
Microsoft.Graph.Teams
Get-Command | Where Source -Like Microsoft.Graph.Teams
Microsoft.Graph.DeviceManagement
Get-Command | Where Source -Like Microsoft.Graph.DeviceManagement
Get-Command | Where Source -Like Microsoft.Graph.Compliance
Searching by Name
The previous information on submodules and cmdlets numbers was mostly an educational exercise and to provide us an idea of the breadth and depth of the cmdlets. If we need to search for a cmdlet based on name to possibly see what cmdlets are available to perform a function (authentication, email, etc) or affect a possible object type (group, user, etc).
Example 1 – ‘Mail’
Get-Command *mail* | Where Source -Like Microsoft.Graph.*
Above is a small subset of the 166 Graph cmdlets with ‘mail’ in the name and as we can see, they cross quite a few submodules as well.
Example 2 – ‘Group’
Get-Command *group* | Where Source -Like Microsoft.Graph.*
Above is a small subset of the 1502 Graph cmdlets with ‘group’ in the name and as we can see, they cross quite a few submodules as well.
Example 3 – ‘License’
Get-Command *licens* | Where Source -Like Microsoft.Graph.*
Above is a small subset of the 24 Graph cmdlets with ‘licens’ in the name and as we can see, they cross quite a few submodules as well.
Searching by URI
Graph resources are referenced by URI or resource URLs and cmdlets also reference these access points. We can pull this detail from the cmdlet with another Graph cmdlet called ‘Find-MgGraphCmdlet’ which reveals other interesting detail on cmdlets:
Example 1 – Mail in URI
Find-MgGraphCommand -ApiVersion v1.0 -Command * | Where URI -like *mail*
This is a small sample of the 146 cmdlets available that have ‘Mail’ in the URI field.
Detailed information on one cmdlet:
Example 2 – License in URI
Find-MgGraphCommand -ApiVersion v1.0 -Command * | Where URI -like *license*
Find-MgGraphCommand -ApiVersion v1.0 -Command * | Where URI -like *teams*
Conclusion
In this article we dove into how to discover cmdlets from the Microsoft Graph PowerShell module. We also saw that we can query cmdlets using Get-Command as well as Find-MgGraphCommand and that these two cmdlets expose different information about the cmdlets. While this method alone may not give us all we need to truly use the cmdlets, it does provide just one more building block for using Graph to access and manage a tenant via these cmdlets. In the next article we will explore permissions that are needed to run cmdlets and how to determine these with PowerShell.
————————————————————————————————————————————–
Comments? Questions?
Future Microsoft Graph PowerShell book in the works by the end of 2023!
Feel free to leave your Comments below! Learn to more efficiently utilize PowerShell to manage Exchange Server, Exchange Online, Microsoft Defender for Office or Microsoft Purview Compliance portals by picking up frequently updated eBooks: