Make Your PowerShell 7 Truly Powerful

Jung-Hyun Nam
Mar 7 · 3 min read
https://twitter.com/PowerShellHero/status/1166871786782371841

Finally, The new version of PowerShell has released in about three years after PowerShell Core 6 released. Many PowerShell fans have been waiting for the latest version, including me. The new PowerShell 7 minimizing the gap between Windows PowerShell 5 and cross-platform version of PowerShell Core 6. Also, more powerful features added to the latest version.

I want to share some tips who wish to configure the PowerShell environment more powerful, but yet friendly.

oh-my-posh

Inspired by oh-my-zsh, oh-my-posh brings powerful console indicators and features to your PowerShell session.

In PowerShell Core 6, PSReadLine was not a built-in module. So before you install the oh-my-posh, you should install the PSReadLine module first. This additional step makes somewhat cumbersome. But in PowerShell 7, PSReadLine included default distribution, so you can just set up oh-my-posh directly.

You can run these commands to configure oh-my-posh for PowerShell.

Next, enable your prompt and change the theme.

Note: Your default terminal font may not render powerline characters correctly at first time. Please lookup https://github.com/ryanoasis/nerd-fonts repository and choose your favorite powerline patched font. Also, if you are looking for CJK balanced font, please consider using the D2Coding font (https://github.com/naver/d2codingfont) from Naver.

Then, open your PowerShell profile script with vim $PROFILE command and paste the below codes.

These code makes your default PowerShell look and feels more improved. You can change the theme of what you want.

PSFzf Module

As you may know, fzf gives you powerful search features for many scenarios. Especially fzf shines when it combined with history search and key binding with Ctrl + R key combination.

PSFzf precisely addresses this scenario. Also, the fzf has written in Golang. So you can use the fzf in macOS, Linux, and even in Windows.

To use the PSFzf module, you should install the fzf on your machine first.

  • On Windows, you can choose between the Chocolatey Package Manager or Scoop Package Manager.
  • On Linux, most package manager provides the fzf package. (Except Ubuntu does not offer the package. You can use the Git installation method alternatively.)
  • On macOS, Homebrew is your best friend.

After you installed the fzf binary, simply install the PSFzf module into your PowerShell.

Finally, let PSFzf overrides default key binding at startup. Paste the below codes.

PowerShell version of k, kubectx, and kubens

If you are stick with Kubernetes every day, you may know or consider shorthand expression of the kubectl.

I’m using the alias K, kubectx and kubens every day. But these scripts are not designed for PowerShell. So I tried to make the own version of each shorthand convention. Naturally, you can use below snippets to your other environments, including Windows.

Paste these codes to your $PROFILE script code and you will get more comfortable PowerShell workspace for DevOps.

Conclusion

I think the real power of PowerShell is, you can write your shell automation code more readable, manageable, and reusable for every operating system, including Windows. It means that no more corner-case considerations are needed. You can just write your PowerShell snippet once and share the code everywhere.

More and more features will arrive at the next version of PowerShell. I can’t wait for that!

Beyond the Windows

DevOps Engineer’s Blog

Jung-Hyun Nam

Written by

DevOps Engineer @ DEVSISTERS, Corp., Microsoft MVP since 2009, Living in S.Korea.

Beyond the Windows

DevOps Engineer’s Blog

More From Medium

More on DevOps from Beyond the Windows

More on DevOps from Beyond the Windows

More on DevOps from Beyond the Windows

Choosing Your Base Image in Windows Container

More on Programming from Beyond the Windows

More on Programming from Beyond the Windows

Running Django Applications in iPad

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade