How to use oh-my-posh with PnPPowerShell

Published Apr 14 2022 10:09 AM 1,374 Views

What is oh my posh?

Oh-my-posh is an amazing prompt engine that does not only pretty up the terminal you use, but it will ease your work. By using an established theme or creating a new one, you get important information directly in the context of your work, highlighted in the way that works best for you. For example:

  • In which repository am I working in?
  • Which branch?
  • When did I execute a command?
  • On which node.js version am I working?

the M365Princess theme by Luise plus environment variables by Anoop

Making good things even better: A while ago, Luise created her own theme and now Anoop had the idea to level it up:

When interacting with Microsoft 365, most of the times we use the Microsoft 365 platform community driven PowerShell module called PnP PowerShell. One of the first commands we execute while using PnP PowerShell, is Connect-PnPOnline to connect to a SharePoint site. We can now see right in the terminal which SharePoint site we are connected to and which Microsoft 365 tenant the SharePoint site lives in.

 

oh-my-posh.png

These are displayed with the help of a couple of environment variables that are set by PnP PowerShell after running the Connect-PnPOnline command.

In the preview below, the connected SharePoint site is /sites/yoursite which is in the tenant named yourtenant.sharepoint.com

 

The original idea to show these values comes from Erwin van Hunen, the father of PnP PowerShell.

How to install oh-my-posh and the theme

To have this experience in Visual Studio Code, complete the following steps:

  1. Install oh-my-posh and posh-git
    • Open the the terminal and run
      • Install-Module oh-my-posh -Scope CurrentUser
      • Install-Module posh-git -Scope CurrentUser
  2. Edit your PowerShell profile in VS Code
    • Open it with code $PROFILE
    • Insert this:
Import-Module oh-my-posh
Import-Module posh-git
Set-PoshPrompt -Theme M365Princess
  1. Install a font
    • Download a font of your choice from Nerdfonts
    • Install a monospace version of that font
    • Open settings in VS Code with CTRL + SHIFT + P and select Preferences: Open settings (JSON)
    • Add (for example) "terminal.integrated.fontFamily": "CaskaydiaCove Nerd Font"
    • Save settings and restart VS Code

Slow prompt?

In case the prompt is responding slow on Windows OS, then one of the reasons might be the oh-my-posh process being blocked by Windows defender. To overcome that, please run PowerShell with elevated permissions (Run as administrator) and execute the following command:

Add-MpPreference -ExclusionProcess "oh-my-posh.exe"

If that doesn’t solve the problem then, execute the following command

Add-MpPreference -ExclusionPath "$env:POSH_PATH\oh-my-posh.exe"

For more information see the comments this issue.

Conclusion

It’s the little things! Of course this is just one puzzle tile, but better overview, crucial information presented in a minimal but nerdy and compelling way helps people to ease their workloads. When working with PnP PowerShell, it’s a game changer to know to which of your tenants and sites you are connected to.

If you like the oh-my-posh and can afford it, go buy Jan, who builds and maintains this awesome open source project, a coffee :hot_beverage:: oh-my-posh repository

sharing is caring

%3CLINGO-SUB%20id%3D%22lingo-sub-3285999%22%20slang%3D%22en-US%22%3EHow%20to%20use%20oh-my-posh%20with%20PnPPowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3285999%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22what-is-oh-my-posh%22%20class%3D%22heading-anchor%22%20id%3D%22toc-hId-394716189%22%20id%3D%22toc-hId-416037770%22%3EWhat%20is%20oh%20my%20posh%3F%3C%2FH2%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fohmyposh.dev%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EOh-my-posh%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%20an%20amazing%20prompt%20engine%20that%20does%20not%20only%20pretty%20up%20the%20terminal%20you%20use%2C%20but%20it%20will%20ease%20your%20work.%20By%20using%20an%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fohmyposh.dev%2Fdocs%2Fthemes%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Eestablished%20theme%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eor%20creating%20a%20new%20one%2C%20you%20get%20important%20information%20directly%20in%20the%20context%20of%20your%20work%2C%20highlighted%20in%20the%20way%20that%20works%20best%20for%20you.%20For%20example%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EIn%20which%20repository%20am%20I%20working%20in%3F%3C%2FLI%3E%0A%3CLI%3EWhich%20branch%3F%3C%2FLI%3E%0A%3CLI%3EWhen%20did%20I%20execute%20a%20command%3F%3C%2FLI%3E%0A%3CLI%3EOn%20which%20node.js%20version%20am%20I%20working%3F%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH3%20id%3D%22the-m365princess-theme-by-luise-plus-environment-variables-by-anoop%22%20class%3D%22heading-anchor%22%20id%3D%22toc-hId-1085277663%22%20id%3D%22toc-hId-1106599244%22%3Ethe%20M365Princess%20theme%20by%20Luise%20plus%20environment%20variables%20by%20Anoop%3C%2FH3%3E%0A%3CP%3EMaking%20good%20things%20even%20better%3A%20A%20while%20ago%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2FLuiseFreese%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3ELuise%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ecreated%20her%20own%20theme%20and%20now%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Fanooptells%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EAnoop%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ehad%20the%20idea%20to%20level%20it%20up%3A%3C%2FP%3E%0A%3CP%3EWhen%20interacting%20with%20Microsoft%20365%2C%20most%20of%20the%20times%20we%20use%20the%20Microsoft%20365%20platform%20community%20driven%20PowerShell%20module%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fpnp.github.io%2Fpowershell%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%3CSTRONG%3EPnP%20PowerShell%3C%2FSTRONG%3E%3C%2FA%3E.%20One%20of%20the%20first%20commands%20we%20execute%20while%20using%20PnP%20PowerShell%2C%20is%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EConnect-PnPOnline%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20connect%20to%20a%20SharePoint%20site.%20We%20can%20now%20see%20right%20in%20the%20terminal%20which%20SharePoint%20site%20we%20are%20connected%20to%20and%20which%20Microsoft%20365%20tenant%20the%20SharePoint%20site%20lives%20in.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22oh-my-posh.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F364244i2D775B32CB4D969C%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22oh-my-posh.png%22%20alt%3D%22oh-my-posh.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EThese%20are%20displayed%20with%20the%20help%20of%20a%20couple%20of%20environment%20variables%20that%20are%20set%20by%20PnP%20PowerShell%20after%20running%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EConnect-PnPOnline%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ecommand.%3C%2FP%3E%0A%3CP%3EIn%20the%20preview%20below%2C%20the%20connected%20SharePoint%20site%20is%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%2Fsites%2Fyoursite%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ewhich%20is%20in%20the%20tenant%20named%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eyourtenant.sharepoint.com%3C%2FCODE%3E%3C%2FP%3E%0A%3CP%3E%3CPICTURE%3E%3CSOURCE%20srcset%3D%22%2Fblog%2Fpost%2Fhow-to-use-oh-my-posh-with-pnppowershell%2Fimages%2Foh-my-posh_hu4b0c5cd0dcd40f4c2af930b5526ab862_72252_800x0_resize_q100_h2_box_3.webp%22%20media%3D%22(min-width%3A500px)%22%3E%3C%2FSOURCE%3E%3CSOURCE%20srcset%3D%22%2Fblog%2Fpost%2Fhow-to-use-oh-my-posh-with-pnppowershell%2Fimages%2Foh-my-posh_hu4b0c5cd0dcd40f4c2af930b5526ab862_72252_1200x0_resize_q100_h2_box_3.webp%22%20media%3D%22(min-width%3A800px)%22%3E%3C%2FSOURCE%3E%3CSOURCE%20srcset%3D%22%2Fblog%2Fpost%2Fhow-to-use-oh-my-posh-with-pnppowershell%2Fimages%2Foh-my-posh_hu4b0c5cd0dcd40f4c2af930b5526ab862_72252_1500x0_resize_q100_h2_box_3.webp%22%20media%3D%22(min-width%3A1200px)%22%3E%3C%2FSOURCE%3E%3CSOURCE%20srcset%3D%22images%2Foh-my-posh.png%22%20media%3D%22(min-width%3A1500px)%22%3E%3C%2FSOURCE%3E%3C%2FPICTURE%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20original%20idea%20to%20show%20these%20values%20comes%20from%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Ferwinvnhunen%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EErwin%20van%20Hunen%3C%2FA%3E%2C%20the%20father%20of%20PnP%20PowerShell.%3C%2FP%3E%0A%3CH2%20id%3D%22how-to-install-oh-my-posh-and-the-theme%22%20class%3D%22heading-anchor%22%20id%3D%22toc-hId-1074774559%22%20id%3D%22toc-hId-1096096140%22%3EHow%20to%20install%20oh-my-posh%20and%20the%20theme%3C%2FH2%3E%0A%3CP%3ETo%20have%20this%20experience%20in%20Visual%20Studio%20Code%2C%20complete%20the%20following%20steps%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EInstall%20oh-my-posh%20and%20posh-git%3CUL%3E%0A%3CLI%3EOpen%20the%20the%20terminal%20and%20run%3CUL%3E%0A%3CLI%3E%3CCODE%3EInstall-Module%20oh-my-posh%20-Scope%20CurrentUser%3C%2FCODE%3E%3C%2FLI%3E%0A%3CLI%3E%3CCODE%3EInstall-Module%20posh-git%20-Scope%20CurrentUser%3C%2FCODE%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3EEdit%20your%20PowerShell%20profile%20in%20VS%20Code%3CUL%3E%0A%3CLI%3EOpen%20it%20with%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ecode%20%24PROFILE%3C%2FCODE%3E%3C%2FLI%3E%0A%3CLI%3EInsert%20this%3A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CDIV%20class%3D%22highlight%22%3E%0A%3CPRE%20class%3D%22chroma%22%20tabindex%3D%220%22%3E%3CCODE%20class%3D%22language-fallback%22%20data-lang%3D%22fallback%22%3E%3CSPAN%20class%3D%22line%22%3E%3CSPAN%20class%3D%22cl%22%3EImport-Module%20oh-my-posh%0A%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22line%22%3E%3CSPAN%20class%3D%22cl%22%3EImport-Module%20posh-git%0A%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22line%22%3E%3CSPAN%20class%3D%22cl%22%3ESet-PoshPrompt%20-Theme%20M365Princess%0A%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3C%2FDIV%3E%0A%3COL%20start%3D%223%22%3E%0A%3CLI%3EInstall%20a%20font%3CUL%3E%0A%3CLI%3EDownload%20a%20font%20of%20your%20choice%20from%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fwww.nerdfonts.com%2Ffont-downloads%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3ENerdfonts%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EInstall%20a%20monospace%20version%20of%20that%20font%3C%2FLI%3E%0A%3CLI%3EOpen%20settings%20in%20VS%20Code%20with%20CTRL%20%2B%20SHIFT%20%2B%20P%20and%20select%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPreferences%3A%20Open%20settings%20(JSON)%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EAdd%20(for%20example)%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%22terminal.integrated.fontFamily%22%3A%20%22CaskaydiaCove%20Nerd%20Font%22%3C%2FCODE%3E%3C%2FLI%3E%0A%3CLI%3ESave%20settings%20and%20restart%20VS%20Code%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH3%20id%3D%22slow-prompt%22%20class%3D%22heading-anchor%22%20id%3D%22toc-hId-1765336033%22%20id%3D%22toc-hId-1786657614%22%3ESlow%20prompt%3F%3C%2FH3%3E%0A%3CP%3EIn%20case%20the%20prompt%20is%20responding%20slow%20on%20Windows%20OS%2C%20then%20one%20of%20the%20reasons%20might%20be%20the%20oh-my-posh%20process%20being%20blocked%20by%20Windows%20defender.%20To%20overcome%20that%2C%20please%20run%20PowerShell%20with%20elevated%20permissions%20(Run%20as%20administrator)%20and%20execute%20the%20following%20command%3A%3C%2FP%3E%0A%3CDIV%20class%3D%22highlight%22%3E%0A%3CPRE%20class%3D%22chroma%22%20tabindex%3D%220%22%3E%3CCODE%20class%3D%22language-ps1%22%20data-lang%3D%22ps1%22%3E%3CSPAN%20class%3D%22line%22%3E%3CSPAN%20class%3D%22cl%22%3E%3CSPAN%20class%3D%22nb%22%3EAdd-MpPreference%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22n%22%3E-ExclusionProcess%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22s2%22%3E%22oh-my-posh.exe%22%3C%2FSPAN%3E%0A%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3C%2FDIV%3E%0A%3CP%3EIf%20that%20doesn%E2%80%99t%20solve%20the%20problem%20then%2C%20execute%20the%20following%20command%3C%2FP%3E%0A%3CDIV%20class%3D%22highlight%22%3E%0A%3CPRE%20class%3D%22chroma%22%20tabindex%3D%220%22%3E%3CCODE%20class%3D%22language-ps1%22%20data-lang%3D%22ps1%22%3E%3CSPAN%20class%3D%22line%22%3E%3CSPAN%20class%3D%22cl%22%3E%3CSPAN%20class%3D%22nb%22%3EAdd-MpPreference%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22n%22%3E-ExclusionPath%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22s2%22%3E%22%24env%3APOSH_PATH%5Coh-my-posh.exe%22%3C%2FSPAN%3E%0A%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3C%2FDIV%3E%0A%3CP%3EFor%20more%20information%20see%20the%20comments%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FJanDeDobbeleer%2Foh-my-posh%2Fissues%2F1904%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ethis%20issue%3C%2FA%3E.%3C%2FP%3E%0A%3CH2%20id%3D%22conclusion%22%20class%3D%22heading-anchor%22%20id%3D%22toc-hId-1754832929%22%20id%3D%22toc-hId-1776154510%22%3EConclusion%3C%2FH2%3E%0A%3CP%3EIt%E2%80%99s%20the%20little%20things!%20Of%20course%20this%20is%20just%20one%20puzzle%20tile%2C%20but%20better%20overview%2C%20crucial%20information%20presented%20in%20a%20minimal%20but%20nerdy%20and%20compelling%20way%20helps%20people%20to%20ease%20their%20workloads.%20When%20working%20with%20PnP%20PowerShell%2C%20it%E2%80%99s%20a%20game%20changer%20to%20know%20to%20which%20of%20your%20tenants%20and%20sites%20you%20are%20connected%20to.%3C%2FP%3E%0A%3CP%3EIf%20you%20like%20the%20oh-my-posh%20and%20can%20afford%20it%2C%20go%20buy%20Jan%2C%20who%20builds%20and%20maintains%20this%20awesome%20open%20source%20project%2C%20a%20coffee%20%3Ahot_beverage%3A%3A%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FJanDeDobbeleer%2Foh-my-posh%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eoh-my-posh%20repository%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Esharing%20is%20caring%3C%2FEM%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-3285999%22%20slang%3D%22en-US%22%3E%3CP%3EGet%20information%20on%20Microsoft%20365%20tenant%20and%20SharePoint%20site%20you%20are%20working%20with%20on%20PnP%20PowerShell%20right%20in%20your%20terminal%20with%20pretty%20oh-my-posh%20theme%20and%20environment%20variables%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22oh-my-posh.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F364243i54A4869ADAD10630%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22oh-my-posh.png%22%20alt%3D%22oh-my-posh.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3285999%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EHow%20to%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Apr 14 2022 10:09 AM
Updated by: