The Term Oh-My-Posh Is Not Recognized as a Name of Cmdlet

Introduction

Recently, I came up with an issue, where I am trying to install oh-my-osh. In general, oh-my-posh is a command line utility that is customizable and portable and helps.

  • Adding colors and fonts to your command prompt
  • Allows to use of a single configuration file across multiple shells or machines

I was following Scott Hansleman’s blog to set up the PowerShell core prompt a little colorful using a PS module called ‘oh-my-posh’. I followed the below steps to install initially.

Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck

Then I ran the notepad profile command to pre-load the modules so that the PowerShell command prompt (I am using PowerShell core here on Windows) looks colorful.

notepad $PROFILE

Notepad

Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme Paradox

When running the PowerShell core normally, then I got the below message.

Running PowerShell Core

This basically says the oh-my-posh is no longer supported by PowerShell. It is required to be installed separately. I have followed the link given in the message.

What is a PowerShell Profile?

A PowerShell profile is a script that runs before the PowerShell starts with pre-declared variables and pre-loaded modules that you can configure. For instance, if you want to have PowerShell windows loaded with some custom modules without you having to run the import modules command you can set up a PowerShell profile file, add the necessary import-module commands, and set up required variables. A sample profile file can look like below.

Import Module posh-git

In this case, the profile script is loaded with posh-git and loads the custom theme for the command prompt which is a ‘paradox’ in this case.

Pre-requisites

For successful installation of the oh-my-posh module, you need to have

  • ‘winget’ installed for Windows 10 / 11 OS.
  • admin privileges to your machine
  • PowerShell core (version 7 or above) installed on your machine.

Clean up Existing oh-my-posh

To clean up the legacy oh-my-posh that comes with legacy modules, please go through the following steps.

Step 1. At first, you need to remove the module-cached files. Open the command prompt or PowerShell prompt of your choice in admin mode and run the following command.

Remove-Item $env:POSH_PATH -Force -Recurse

Step 2. The next step is to remove the ohmyposh PowerShell modules.

Uninstall-Module oh-my-posh -AllVersions

Step 3. Delete the import command from the $PROFILE file. Look for the following line and remove it from the $PROFILE file.

Import-Module oh-my-posh

Installing latest oh-my-posh

Follow the below steps to install Oh My Posh.

Step 1. Open the PowerShell Core command prompt as administrator, Run the below command.

Command prompt

winget install JanDeDobbeleer.OhMyPosh -s winget

This installs

  • oh-my-posh.exe executable
  • themes

Step 2. Now open Notepad $PROFILE from the PowerShell command prompt and add the following lines.

Import-Module posh-git
Oh-my-posh init pwsh –config “$env:POSH_THEMES_PATH\paradox.omp.json” | Invoke-Expression

PowerShell Command prompt

Note. You can also have your own themes. The themes can be found at  C:\Users\<USERNAME>\AppData\Local\Programs\oh-my-posh\themes.

Themes

Just replace the theme name with your required one.

Step 3: You should see the PowerShell command prompt with colored themes.

Colored theme

Conclusion

Thus in this article, you have understood, what the oh-my-posh command utility is, and benefits of using it, and how to install the latest version of oh-my-posh using PowerShell core with colored themes.

References

  1. https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.4
  2. https://www.hanselman.com/blog/how-to-make-a-pretty-prompt-in-windows-terminal-with-powerline-nerd-fonts-cascadia-code-wsl-and-ohmyposh
  3. https://ohmyposh.dev/
  4. https://ohmyposh.dev/docs/migrating
  5. https://ohmyposh.dev/docs/installation/windows


Similar Articles