Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Do you want to run the Connect-MgGraph command and avoid the browser prompting you for authentication? This is a hands-on guide where I show how to accomplish that.

I am executing the commands on this guide using PowerShell 7. The commands will work on PowerShell 5 but it may behave slightly differently.

Step 1: Install the Required Modules

To run the Connect-MgGraph command and avoid the browser prompting authentication, you must install two PowerShell modules. Specifically, you require the Az.Accounts and Microsoft.Graph.Authentication modules.

Run the commands below to install the two modules:

Install-Module Az.Accounts, Microsoft.Graph.Authentication
Import-Module Az.Accounts, Microsoft.Graph.Authentication

Step 2: Authenticate to Microsoft Graph

As I hinted in my introduction, retrieving the Azure token is the first step to connecting to Microsoft Graph. This step is achieved by connecting to your Azure account.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

After that, you will use the token to authenticate to Microsoft Graph. Here are the detailed steps:

Popular on Amazon
Sale
Logitech MK120 Full Size Wired Keyboard and Mouse Combo - Black | Full size wired keyboard, optical wired mouse, USB plug-and-play, Windows only, pc and laptop compatible
  • Durable and Reliable: This USB keyboard features a curved space bar, spill-resistant design (2), durable keys that can withstand 10 million keystrokes, and sturdy, adjustable tilt legs
  • Comfortable, Familiar Typing: You’ll enjoy a comfortable and familiar typing experience thanks to the deep-profile keys and standard layout with full-size F-keys and number pad
  • Full-size Sculpted Mouse: The high-definition optical USB mouse puts comfort and control in your hands with smooth, accurate tracking and an ambidextrous shape that feels good hour after hour
  • Simple Set-Up: Simply plug the keyboard and mouse into the USB ports on your desktop, laptop, or netbook and you're ready to work; compatible with Windows 7, 8, 10 or later
  • Clear and Convenient: The bold, bright white and long-lasting characters make the keys on this PC or laptop keyboard easy to read and extra durable
  1. Get the credentials you require to authenticate to Azure from PowerShell by running the command below:
$credential = Get-Credential <Azure  logon email>
Replace the <Azure logon email> placeholder with your actual Azure login email. When you execute the command, PowerShell will prompt you to enter the password for the Azure login.
  1. Next step, log in to Azure with the Connect-AzAccount command…
Connect-AzAccount -Credential $credential 

The above command will take a short while to complete as it authenticates to Azure using the creds saved in the $credential variable. Once you connect successfully, PowerShell displays information about your Azure tenant.

The above command will take a short while to complete as it authenticates to Azure using the creds saved in the $credential variable. Once you connect successfully, PowerShell displays information about your Azure tenant.
  1. Now that you’ve signed in to Azure, the next step of this section is to retrieve the Azure Access token you require to authenticate to Microsoft Graph API.
$AzAccessToken = (Get-AzAccessToken -ResourceTypeName MSGraph -ErrorAction Stop).token
  1. Finally, execute the Connect-MgGraph command specifying the $AzAccessToken variable – this provides the auth you require and stops the command prompting you to authenticate via the browser.
Connect-MgGraph -AccessToken $AzAccessToken -ErrorAction Stop

To confirm that you’ve successfully authenticated to Microsoft Graph, you will receive a “Welcome To Microsoft Graph!” message.

Finally, execute the Connect-MgGraph command specifying the $AzAccessToken variable - this provides the auth you require and stops the command prompting you to authenticate via the browser.

Step 3: Manage Azure with the Microsoft Graph Commands

Having shown how to run the Connect-MgGraph command and bypass the browser prompt for authentication, I have met the purpose of this article.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

However, I like to share a few Azue tasks that you can perform using the Microsoft Graph module cmdlets. I decided to include these examples as a way to confirm that the Microsoft Graph API connection worked.

Also popular on Amazon
Sale
Logitech MK270 Full Size Wireless Keyboard and Mouse Combo - Black | Full size keyboard with spill-resistant design, compact ambidextrous mouse, connect via single included USB-A Nano Receiver
  • Reliable Plug and Play: The USB receiver provides a reliable wireless connection up to 33 ft (1), so you can forget about drop-outs and delays and you can take it wherever you use your computer
  • Type in Comfort: The design of this keyboard creates a comfortable typing experience thanks to the low-profile, quiet keys and standard layout with full-size F-keys, number pad, and arrow keys
  • Durable and Resilient: This full-size wireless keyboard features a spill-resistant design (2), durable keys and sturdy tilt legs with adjustable height
  • Long Battery Life: MK270 combo features a 36-month keyboard and 12-month mouse battery life (3), along with on/off switches allowing you to go months without the hassle of changing batteries
  • Easy to Use: This wireless keyboard and mouse combo features 8 multimedia hotkeys for instant access to the Internet, email, play/pause, and volume so you can easily check out your favorite sites

Let’s start by running the Get-MgContext command. This command displays the scope of the session.

Get-MgContext | Select-Object -ExpandProperty Scopes

The screenshot below shows the result of the above command. To learn more about Microsoft Graph scopes, read the Microsoft Graph permissions reference.

Another command task we can perform is to find an Azure AD user with the Get-MgUser command. In my example below, I want to return Azure AD users with DisplayNames that start with “v.”

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Get-MgUser -Filter "startsWith(DisplayName, 'v')"
Run Connect-MgGraph without Browser Prompt Authentication

Another great example of managing Azure AD with Microsoft Graph is displaying and creating groups. To view an Azure AD group, run the Get-mgGroup command.

Also popular on Amazon
EDJO Wired Keyboard and Mouse Combo,Ergonomic with Palm Rest,Full Size | 104 Keys Layout,USB Plug-and-Play,12 Multimedia Shortcuts,Computer Optical Corded Mouse,for Windows,Mac OS,Desktop/Laptop/PC
  • 【104 Keys Layout and Ergonomic Design】EDJO full-sized wired keyboard is ergonomically designed with palm rest and foldable stand that can make it typing more comfortable. Anti-slip design on the bottom of the keyboard can prevent the keyboard from moving while typing, which is more stable to use.
  • 【Plug & Play and Stable Connection】This wired keyboard mouse combo is plug and play, no needed install any drivers, wired connection can provide more stable signal input than wireless connection, more responsive typing.
  • 【Optical Wired Mouse】This is a optical wired mouse that can works well on a smooth surface even without a mouse pad. The mouse is symmetrical design,suitable for all users, very comfortable to hold, keeps your hands relaxed even after long time of work.
  • 【12 Multimedia Shortcuts】The wired keyboard has 12 multimedia shortcuts combinations that is convenient to instant access music, volume, computer, mail, etc. it can improve work efficiency greatly. There are caps lock Indicator and number lock Indicator in the upper right corner of the keyboard. (Note: Some multimedia function are not available with Mac OS)
  • 【Widely Compatible and 12 Months Warranty】EDJO wired keyboard and mouse combo is widely compatible with Windows XP/Vista/7/8/8.1/10, Mac and other operating systems. Suitable for Desktops, Chromebook, PC, Laptop, Computer, and more. Our product has 12 month's warranty, if you encounter any problems with the product, please contact us via email, we will provide you with excellent after-sales service.

My example below returns a group with the specified Id.

Get-mgGroup -GroupId 001fa802-90c5-4753-834b-ef5450d6ff78

Finally, I can create a new Azure AD security group with the New-MgGroup command. See my command below for a sample command that creates a group called Office Admins.

New-MgGroup -DisplayName 'Office Admins' -MailEnabled:$False  -MailNickName 'OfficeAdmins' -SecurityEnabled
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

1. What is the difference between Connect-MsGraph and Connect-MgGraph?

As far as I am aware, the valid cmdlet is Connect-MgGraph, which is from the Microsoft.Graph PowerShell module.

If the Connect-MsGraph cmdlet exists, it may be from another PowerShell module, not officially related to the MS Graph API module.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
2. How do I connect to MgGraph?

The faster method to connect to Microsoft Graph via PowerShell is by running the Connect-MgGraph command.

Also popular on Amazon
Sale
Wireless Keyboard and Mouse Combo Silent for Office and Home(Avocado Green) | 2.4G Full Size Silent Cordless Keyboard with Tilt Legs,3-Level DPI Quiet Mouse,for Windows/Mac OS/Desktop/Laptop/PC
  • 【Lag-free & Efficient】Stable and reliable connection of wireless keyboard and mouse is up to 10m(33ft). This combo share a nano USB receiver, no need to take up additional USB ports (Also the wireless keyboard and mouse can also be used separately). Plug and play, no software needed,convenient and efficient.
  • 【Quiet & Type in Comfort】Wireless keyboard come with adjustable height tilt legs to increase comfort and prevent your wrists injury when typing for a long time.Our wireless keyboard adopts a silent structure. Soft membrane keys provide a quiet and comfortable typing experience.The wireless mouse is quiet without any clicking sound also.So whether at home or in the office, you can use this combo as you please without worrying about disturbing others.
  • 【Full Size Keyboard】This keyboard saves desktop space while retaining its full size.The full size wireless keyboard with numeric keypad and 12 multimedia shortcut keys, such as play/ pause, volume increase and decrease, and search, to help you improve work efficiency.
  • 【Auto Power Saving Function】Wireless keyboard and mouse have a smart auto-sleep mode to save power for long battery life. They will enter sleep mode after stop using a while(Refer to the instructions for details). Unplug the receiver or after the PC shutdown, they will enter sleep mode too.You can press any keys to wake. (battery life may vary based on user and computing conditions)
  • 【Comfortable Optical Mouse】This silent wireless mice provides 3 adjustable DPI (800/1200/1600) to meet your different needs in terms of sensitivity.The compact lightweight design of wireless mouse and a hand-friendly contoured shape for all-day comfort, and smooth, precise tracking. Very suitable for office and daily use.
3. How do I disconnect Microsoft Graph PowerShell?

Run the Disconnect-mgGraph command to disconnect from the Microsoft Graph PowerShell session.

4. What is the difference between PowerShell Azure AD and Graph?

The Azure AD PowerShell module is used to manage Azure Active Directory only. On the other hand, the Microsoft Graph PowerShell module can be used to manage Azure AD and other Microsoft Cloud resources.

5. How do I cConnect to Microsoft Graph in PowerShell?

By running the Connect-MgGraph command.

Conclusion

When you run the Connect-MgGraph command, PowerShell prompts you for authentication via the default browser on your PC. As I have shown in this guide, you can avoid this by first running the Connect-AzAccount command.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Once connected to your Azure account and getting the required access token, you can run the Connect-MgGraph and connect straight from the PowerShell console.

Thank you for reading and I hope you found the guide helpful. Let us know by sharing your thoughts with the comment form at the bottom of this page.

Alternatively, you can respond to the “Was this page helpful?” question below.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply. Prices as of November 19, 2026 5:12 pm GMT.