I hope this article helped you to get started with the MgGraph module. At the moment of writing is the documentation still a bit thin, so it’s a lot of trial and error to write scripts with it. It can be a bit challenging to find the correct cmdlets of the Microsoft Graph SDK Module, but it’s great that one module allows us to interact with all Microsoft services. When you are working with Graph in PowerShell you can add additional scopes to your session by simply using the Connect-MsGraph command again with the new permissions. Grant permission to Microsoft Graph PowerShell Some scopes require to grant permission on behalf of your organization. You will need to authenticate and grant permission. Next, we want to connect to Graph with the scopes that we need: Connect-MgGraph -Scopes "","" I am going to use the Beta version, but if you want to create a script for production, then you won’t need to select it. So let’s connect to Microsoft Graph.įirst, we need to set the API version that we want to use. We now know which profile we want to use and how to find the scope that we need. You don’t need to add all scope, they are listed from least to most privileged. You can select in the left menu one of the entities that you want to work with and then view the required permissions. The other option is to use the Rest API Reference. You will need to at at least one of the scopes mentioned in the Permission tab when connecting to MS Graph in PowerShell. Select an Sample Query on the left side.But it will also list the required permission for the call. It comes with a lot of examples calls to help you get started. The Microsoft Graph Explorer is a great tool to test out API calls to Microsoft Graph. But there are two good sources that you can use to determine which scopes you will need to specify: Finding Microsoft Graph Scopesįinding the right scope can be a bit challenging at the beginning. So when you want for example to export or view the Azure AD users, you only need to have permission. Graph offers access to all APIs from Microsoft. The other important step is that you will need to specify the scopes that you want to use. But you can also change this to the Beta version of the API. By default, the module will use the stable version of the API. There are two things important when connecting to Microsoft Graph, you can specify the API version and you will need to define the scope. When installing all modules it can take a couple of minutes before the installation is completedĬonnecting to Microsoft Graph from PowerShell Type Y to install from the Untrusted Repository Install-Module Microsoft.Graph -Scope CurrentUser – Select Windows PowerShell or Windows Terminal (on Win 11)Įnter the following command in PowerShell to install the module: – Right-click on Start or press Windows Key + X It’s also possible to install it for all users, but then you will need to open PowerShell with elevated permissions. We are going to install the Microsoft Graph module only for the current user. You can view all available modules with the following command: Find-Module Microsoft.Graph* Note Make sure that you install atleast the module when installing individual modules We can install them all at once, but you might want to consider installing only the modules that you really need. The Microsoft Graph SDK Module exists, at the moment, out of 38 modules. Installing the Microsoft Graph Module in PowerShell The Azure AD Module, for example, doesn’t work on PowerShell 7. This means that we could also use the module to interact with SharePoint, Exchange Online, Compliance, etc.Īnother advantage of the module is that it supports PowerShell 7 and above. So it’s important to rewrite all your scripts that use the Azure AD Module to the Microsoft Graph module.Īs mentioned, the Microsoft Graph PowerShell SDK allows us to interact with all APIs from Microsoft. This means that calls made with the Azure AD Module won’t get a response anymore. On June 30, 2022, the Azure AD Graph endpoint will be deprecated. The other modules that we use to interact with Microsoft 365 don’t seem to be replaced by it at the moment. At the moment it only seems to replace the Azure AD module. The Graph module is actually called the Microsoft Graph PowerShell SDK and is a wrapper for all Microsoft Graph APIs. In this article, I will explain how to install the Microsoft Graph Module and how to connect to it using the different permissions. The new Microsoft Graph Module comes with a lot of cmdlets to make interacting with the services a lot easier. We could already use the Graph API with the help of Invoke-Webrequests calls, but that was not really easy to work with. This is no longer necessary with the Microsoft Graph SDK Module for PowerShell. To do this from PowerShell, we always had to install different modules and make different connections. The Microsoft Graph API allows us to interact with all Microsoft services through a single source.
0 Comments
Leave a Reply. |