{"id":4715,"date":"2025-11-23T13:37:16","date_gmt":"2025-11-23T13:37:16","guid":{"rendered":"https:\/\/geekmungus.co.uk\/?p=4715"},"modified":"2025-11-23T13:37:16","modified_gmt":"2025-11-23T13:37:16","slug":"install-and-use-microsoft-graph-developer-machine","status":"publish","type":"post","link":"https:\/\/geekmungus.co.uk\/?p=4715","title":{"rendered":"Install and Use Microsoft Graph (Developer Machine)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The document provides a simple guide to how to install and use the Microsoft Graph and Microsoft Exchange Online PowerShell modules to interact with Microsoft 365 infrastructure for the purposes of administering the Microsoft 365 infrastructure and applications; i.e. how to setup your Developer Machine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You may be able to install modules without administrative rights by adding the &#8220;scope&#8221; argument, for example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Install-Module -name &lt;whatever> -scope CurrentUser<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The Microsoft Graph is essentially an API that allows you as an administrator\/developer to access and manipulate Microsoft 365 infrastructure via the API. When using Microsoft Graph you require your account to have the relevant privileges.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"InstallandUseMicrosoftGraph(DeveloperMachine)-Step1-InstallModule\">Step 1 &#8211; Install Module<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To install the Module run PowerShell as an Administrator.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Install-Module -Name Microsoft.Graph<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Answer &#8220;Yes&#8221; to trusting the untrusted repository if\/when prompted, then wait for the installation to complete (it may take a few minutes to complete).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"InstallandUseMicrosoftGraph(DeveloperMachine)-Step2-ExampleConnection\">Step 2 &#8211; Example Connection<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To verify that the connection has been made successfully, we&#8217;ll connect to Microsoft 365, in this example we&#8217;re just connecting with the Scope of &#8220;User.Read.All&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Why use Scopes? The use of Scope ensures that you are restricting what your account will do with the connection it has, its part of OAuth2 and is good security practice. If you&#8217;re going to, as in this example, just obtain a list of users within Entra ID, i.e. just reading information, by connecting with a &#8220;User.Read.All&#8221; scope we don&#8217;t risk accidentally changing information.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First import the module, you may not need to do this if you&#8217;ve just installed it, but subsequently you may need to do this before running the connect:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Import-Module -Name Microsoft.Graph<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now make the connection.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Connect-MgGraph -Scopes \"User.Read.All\" &#91;-Tenant-Id &lt;Tenant ID>]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ll now see a box asking you to login. You&#8217;ll then be redirected to your SSO provider (e.g. OKTA) where you may need to provide a MFA challenge response.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"408\" height=\"296\" src=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2025\/11\/image-15.png\" alt=\"\" class=\"wp-image-4720\" srcset=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2025\/11\/image-15.png 408w, https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2025\/11\/image-15-300x218.png 300w\" sizes=\"auto, (max-width: 408px) 100vw, 408px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Once connected you should see the following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"738\" height=\"267\" src=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2025\/11\/image-14.png\" alt=\"\" class=\"wp-image-4719\" srcset=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2025\/11\/image-14.png 738w, https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2025\/11\/image-14-300x109.png 300w\" sizes=\"auto, (max-width: 738px) 100vw, 738px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"InstallandUseMicrosoftGraph(DeveloperMachine)-Step3-PerformaTestQuery\">Step 3 &#8211; Perform a Test Query<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s get a list of all our Microsoft 365 user accounts, so now run the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$users = Get-MgUser\n$users | Select-Object DisplayName, UserPrincipalName, Mail<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And we now get our output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"133\" src=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2025\/11\/image-16-1024x133.png\" alt=\"\" class=\"wp-image-4721\" srcset=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2025\/11\/image-16-1024x133.png 1024w, https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2025\/11\/image-16-300x39.png 300w, https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2025\/11\/image-16-768x100.png 768w, https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2025\/11\/image-16-1536x199.png 1536w, https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2025\/11\/image-16.png 1572w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"InstallandUseMicrosoftGraph(DeveloperMachine)-Step4-Disconnect\">Step 4 &#8211; Disconnect<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Once you&#8217;ve finished your work, you then need to disconnect, although not essential it is recommended.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Disconnect-MgGraph<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Additional Notes<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Install-Module PowerShellGet -Force\nInstall-Module ExchangeOnlineManagement\nImport-Module ExchangeOnlineManagement\n\nInstall-Module MSOnline\nInstall-Module AzureAD\nImport-Module AzureAD<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The document provides a simple guide to how to install and use the Microsoft Graph and Microsoft Exchange Online PowerShell modules to interact with Microsoft 365 infrastructure for the purposes of administering the Microsoft 365 infrastructure and applications; i.e. how to setup your Developer Machine. You may be able to install modules without administrative rights &#8230; <a title=\"Install and Use Microsoft Graph (Developer Machine)\" class=\"read-more\" href=\"https:\/\/geekmungus.co.uk\/?p=4715\" aria-label=\"Read more about Install and Use Microsoft Graph (Developer Machine)\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":4282,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54,14,60],"tags":[],"class_list":["post-4715","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-365","category-microsoft-windows","category-powershell"],"_links":{"self":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/4715","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4715"}],"version-history":[{"count":1,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/4715\/revisions"}],"predecessor-version":[{"id":4722,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/4715\/revisions\/4722"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/media\/4282"}],"wp:attachment":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}