Displaying the Connected Account for Microsoft Graph on the Terminal prompt

Like most developers, I am running the Windows Terminal and have customized my prompt using the oh-my-posh module. (Yes, PowerShell. I used a shell of some sort back in the AIX days, but I just can't get up to speed on the modern shells in WSL...) My custom prompt is a bit minimal. I've found that I don't want a lot of stuff in my face all the time. I prefer an in-context display.

My prompt shows me what I need to know about the context of the system and path:

  • The current directory. I primarily work in two different paths. \Repos when writing code that needs to be committed to a repository, and \Dev when I am researching/learning/hacking. But I don't really need to know the entire path, so I use icons to represent these top-level folders.
  • Git status. posh-git is essential, showing the branch and status of the local index
  • Dev Framework. A simple icon to indicate if the folder contains a .Net or NodeJs project.
  • Operating system. While I'm not conversant in Linix shells, I am occasionally in that OS. So another icon to indicate the operating system.
  • Current Machine. With cloud shells and codespaces and remote VSCode instances, it is helpful to know on which machine the commands are running. (I cannot count hom many times I had a command fail because I was running on some cloud environment which doesn't have the same stuff as my machine...)

The prompt takes care of the larger context. Like when returning to the shell after a meeting or coffee break. There are other instances where a context is very important -- which Azure subscription is active or which tenant is connected in the CLI for Microsoft 365. I would always just run a show or status command to verify. But this week, I came across a blog post that pointed me to the Magic Tooltips module for PowerShell. A tooltip with the context I need when I need it!

Magic Tooltip provider for Microsoft Graph

Readers of this blog likely use the Microsoft Graph PowerShell module or the CLI for Microsoft 365 quite often. So, I extended the Magic Tooltip module to include a providers for those utilities.

The tooltip will return the Account name from the Get-MgContext cmdlet and the user name from the m365 status command. The display of the tip can be customized just like all the others in the module.

The module is available in the PowerShell gallery.

In cooperation with Travis, I have taken over ownership of the repository. Since I don't use AWS or Kubernetes, please open an issue if I broke those providers.

I hope you find the module helpful. I certainly do!