I will keep this short.
Code 32 will set Foreground to Green.
“`r`n” <- this eqivalent to \n
newline character
additionaly we can set the variable
Now use the prompt
function in PowerShell to set the command prompt prefix.
That’s it, Now we have a Kali Linux-like command prompt.
Additionally, you can add it to the PowerShell profile path to make it run at startup.
To get the profile path run:
Hi 👋🏻! Today I’m gonna talk about how I setup windows powershell on my windows machine. As a developer, I think having a nice looking terminal and some good useful tools can push towards being a little more productive.
Terminal Application
There are many terminal application for windows, but my favourite is the pre packaged Windows Terminal App. It is :
- Visually Appealing
- Highly customizable
- Tabs Support.
Customizing the Appearance of Windows Terminal
First and foremost, set the Windows Terminal as your default Terminal App.
Access your settings with a quick Ctrl + ,
shortcut. Within the settings menu, find the option to change the default Terminal Application for your machine, and select windows terminal
from the dropdown.
With your default terminal all sorted! 💫
Now it’s time to give it a fresh look. I’m all about that cool acrylic aesthetic in my Terminal App.
Open settings 👉, then, on the left-hand-side menu, head to 👉 Profiles, and within that, navigate to 👉 Defaults. Inside the default settings, you’ll find 👉 Appearance. Now, here’s where you can tweak the theme to match your style. I, for one, love to throw in a Background Image and give the Terminal a bit of blur for that extra flair.
Installing Scoop
Scoop is your go-to Windows package manager, much like Ubuntu’s apt and Fedora’s dnf. It simplifies the management of apps and binaries on your Windows machine. With a single command, you can easily update, install, or delete binaries, eliminating the need for manual configuration of environment variables and paths. Scoop offers various buckets filled with a wide range of apps, and it even makes font installation a breeze.
Before we start customizing the prompt I recommend installing the SCOOP package manager for windows, It will make our work very easy moving froward.
In your terminal run these commands one by one:
This will install SCOOP in your system.
NERD Font Installation with Scoop
Before customizing your prompt with glyphs and symbols like the GitHub or folder icons, you’ll need to install a NERD font. Regular fonts just can’t handle these unique characters, but the NERD fonts have got you covered. You can explore other nerd fonts at (https://nerdfonts.com).
My personal favorite NERD font is Cascadia-Code, and here’s where the Scoop magic comes into play. If you’ve ever attempted to install a custom font, you’re aware that it often involves multiple steps. Scoop simplifies the process to just one command. Here’s how it’s done:
- Start by adding the NERD Font bucket to your Scoop setup:
scoop bucket add nerd-fonts
- Next, install the Cascadia Code NERD font with this command:
scoop install Cascadia-Code
This straightforward process will add the Cascadia-Code font to your system, making it available for you to use.
Changing Your Terminal Font
Now that you have the NERD font installed, it’s time to change your terminal font to Cascadia-Code. Here’s how to do it:
- Navigate to your terminal’s settings.
- Look for “Defaults” and then “Appearance.”
- In the “Font Face” option, select “Cascadia-Code.”
With these simple steps, you’ll have your terminal decked out with the NERD font of your choice, ready to make your prompt uniquely yours.
Customizing the prompt using OH-MY-POSH.
Oh-My-Posh, is my favourite tool for making my prompt look super cool. It gives my terminal a unique, fancy style. Oh-My-Posh makes it super easy. A nice prompt makes a dev life easier.
Getting Oh-My-Posh Installed
scoop bucket add main
Get yourself oh-my-posh.
scoop install oh-my-posh
Now that oh-my-posh is installed its time to configure our windows profile script.
Setting Up Your PowerShell Profile
PowerShell profile, it’s like a special script that runs whenever you start up PowerShell. You can do all sorts of things with it to make your PowerShell experience more awesome. You can add shortcuts, like nicknames, and extra tools that load up when you start PowerShell. Plus, you can make your own special functions to fit the way you work. It’s like a power-up for PowerShell!
To open your PowerShell profile in Notepad, just type this command:
If you come across an error, don’t worry! You can fix it with this command:
New-Item -Path $PROFILE -Type File -Force
Give it a try, and then open your profile again. If you haven’t made any changes before, your profile will be empty.
To make your prompt look like mine, add this line to your profile and save it:
After saving, close and reopen the terminal to reload the profile. It’ll make your PowerShell prompt like mine and everything will work together smoothly.
Sure, let’s briefly discuss how to install two essential PowerShell modules: “Terminal Icons” and “PSReadLine.”
Install Terminal Icons.
- Open PowerShell.
- Use the following command to install Terminal Icons:
- You may be prompted to install the module from the PSGallery repository. Confirm the installation.
Now, you have Terminal Icons installed, and it will automatically enhance your terminal interface with icons for files and folders, making it easier to navigate.
Now add this line to your profile
Import-Module -Name Terminal-Icons
Install PSReadLine
- Open PowerShell.
- Use the following command to install PSReadLine:
- Confirm the installation if prompted.
Once PSReadLine is installed, it will significantly improve your PowerShell command line editing capabilities. You can customize it further by modifying your PowerShell profile.
Now append this line to your profile
Import-Module -Name Terminal-Icons
These modules, Terminal Icons and PSReadLine, can enhance your PowerShell experience by providing a more visually appealing interface and improving your command line editing capabilities.
Now reload your poweshell by closing and reopening the terminal.
Custom Functions for Enhanced PowerShell Workflow
In PowerShell, you can tailor your experience by adding custom functions that simplify common tasks and streamline your workflow. I use the below functions to make my life easier.
Gcom – Simplify Git Commits
The gcom
function streamlines the process of committing changes in a Git repository. It’s perfect for those who frequently make Git commits. Here’s how it works:
When you run gcom "Your commit message here"
, it automatically stages all changes and commits them with the provided message. No need to run separate git add
and git commit
commands.
Lazyg – Commit and Push in One Step
For an even more streamlined Git workflow, the lazyg
function takes the automation a step further. It stages changes, commits with your message, and then pushes the changes to the remote Git repository:
Use it like this: lazyg "Your commit message here"
. This “lazy” approach automates multiple steps, making your Git interactions even more efficient.
Which – Locate Command Definitions
The which
function is a handy utility for pinpointing the location of a specific command or function within your PowerShell environment. It takes a command name as an argument and returns its definition. For example:
Running which Get-ChildItem
will reveal the definition of the Get-ChildItem
command in your environment.
Whichdir – Find Command Directories
Similar to which
, the whichdir
function returns the directory path where a command or function is defined. It uses the Split-Path
cmdlet to extract the directory path:
Executing whichdir Get-ChildItem
will provide the directory where Get-ChildItem
is defined.
By adding these custom functions to your PowerShell profile, you ensure they are available each time you open PowerShell. They not only simplify Git-related tasks but also help you explore your PowerShell environment efficiently.
Tailoring Your PowerShell Experience
Welcome to the world of customizing PowerShell, where you can transform this already formidable tool into a finely tuned instrument tailored to your specific needs. In this article, we will delve deep into the art of PowerShell customization, exploring the myriad ways in which you can personalize your PowerShell environment, scripts, and functions to enhance your productivity, boost your efficiency, and simplify the management of your systems.
https://youtube.com/watch?v=LuAipOW8BNQ%3Ffeature%3Doembed
Understanding the Essence of PowerShell
PowerShell, developed by Microsoft, acts as a multifaceted framework, offering a platform to execute automation tasks, general scripting, and a plethora of other functionalities, expanding the horizons of what one can achieve with it. It operates based on the .NET framework and is ingrained with extensive compatibility, enabling interaction with virtually all functions and features within the Windows operating system.
Evolution and Integration of PowerShell
Object-Oriented Nature of PowerShell
Interactivity and Scripting in PowerShell
PowerShell can be utilized in two primary manners:
Interactive Mode via the Shell:
Scripting Language Mode:
Choosing an Editor for PowerShell
PowerShell’s Comprehensive Abilities
A Comprehensive Guide
PowerShell, the versatile and powerful scripting language and automation framework developed by Microsoft, has seen various versions over the years. Understanding which version you have and which ones are compatible with your Windows operating system can greatly enhance your scripting capabilities. In this guide, we’ll delve into the nuances of PowerShell versions and how to check your current version.
Windows 7: The Starting Point
Default Version: Windows 7 comes with Windows PowerShell version 2.0 pre-installed.
Upgrading to the Latest: If you’re still using Windows 7 and wish to experience the latest features of PowerShell (currently at version 5.0 at the time of writing), you’ll need to install the Windows Management Framework update.
Windows 8: A Unique Versioning Scenario
Windows 8 introduces an interesting twist to PowerShell versioning:
Range of Versions: Windows 8 allows you to run PowerShell versions 2.0 through 3.0, but it restricts you from running versions 4.0 and above.
Windows 8.1: Embracing Version 5.0
Progression: Windows 8.1 takes a leap forward, permitting you to run PowerShell version 5.0.
Windows 10: PowerShell Integration
- Default Version: Windows 10 comes with PowerShell version 5.0 pre-installed, seamlessly integrated into the operating system;
- Staying Current: With Windows 10’s automated update system, keeping your PowerShell version up to date (5.1 and beyond) is almost effortless.
PowerShell Core: Cross-Platform Versatility
PowerShell Core, a cross-platform iteration of PowerShell, is designed to work on Windows, macOS, and Linux. It has its own versioning structure, which may differ from Windows PowerShell.
Check Your PowerShell Version: A Step-by-Step Guide
Now that you’re aware of the PowerShell versions in different Windows environments, let’s explore how to check your current version:
- Open PowerShell: To begin, open PowerShell by hitting the Windows key or clicking the Start icon/button. Type in ‘PowerShell’ and select ‘Windows PowerShell.’;
- Pin to Taskbar: Consider pinning PowerShell to your taskbar for quick and easy access. This convenient tip can save you time in the long run;
- Using the $host Variable: PowerShell stores version information in a dedicated variable, $host. To check your PowerShell version, type “$host” into your console and press Enter. This will display detailed host information, including the version;
- Retrieve the Latest Version: If you’re only interested in the version number, type “$host.Version” to display the Version property exclusively;
- Major Version Check: To specifically retrieve the major version, use “$host.Version.Major.”
Functionality of PowerShell
PowerShell operates primarily through the execution of commands, offering an interpretative lens to comprehend the resulting output effectively. It employs a structure where every element either exists as or is transformed into an object. Here, an object can be perceived as an entity upon which actions can be performed using various methods, and from which information can be obtained through properties.
Grasping the Essentials of PowerShell
Before delving into the customization of the environment using PowerShell, it is crucial to understand some fundamental concepts. A significant aspect of learning PowerShell is experiential, focusing on practical engagement rather than purely theoretical understanding. Thus, don’t be overly concerned about mastering the terminologies from the get-go; instead, explore and learn through implementation.
The Simplicity of ‘Hello World’
Executing Methods and Understanding Objects
Detailed Exploration of Object Types and Method Application
Practical Learning and Exploration
Unveiling the Power of PowerShell Networking Tools
When it comes to network diagnostics and troubleshooting in PowerShell, two go-to commands are ‘Ping’ and ‘Test-Connection.’ While ‘Ping’ is undoubtedly a household name for anyone dealing with network issues, ‘Test-Connection’ offers a deeper dive into network testing capabilities. Let’s embark on a journey to understand the nuances and potentials of these commands.
Ping: A Familiar Friend
Ping, a widely known utility, serves as the initial tool to check network connectivity. By typing ‘Ping Google.com’ into your PowerShell terminal, you can initiate a simple connection test to the Google server. This provides a quick insight into whether you can reach Google’s servers or not. But let’s not stop there; there’s more to explore.
Tips for Effective Pinging:
- Specify the number of packets to send using the ‘-n’ option: Ping Google.com -n 5 sends five packets for more reliable results;
- Understand response times: Analyze the ‘Round-Trip Time’ to gauge network performance;
- Use ‘-t’ for continuous pinging: Ping Google.com -t allows you to continuously monitor the connection.
Test-Connection: The Powerhouse of Network Testing
Now, let’s shift our focus to the versatile ‘Test-Connection’ command. Executing ‘Test-Connection Google.com’ will reveal a richer set of information compared to ‘Ping.’ This includes details on packet loss, response times, and more. But what makes ‘Test-Connection’ stand out?

Unveiling the Power of Test-Connection:
- Accessing Help: To unlock the full potential of ‘Test-Connection,’ use ‘Get-Help Test-Connection.’ It provides insights into various options and functionalities;
- Updating Help Files: If you encounter missing help files, run PowerShell as Administrator and execute ‘Update-Help’ to ensure you have the latest guidance;
- Utilizing ‘-ComputerName’ Parameter: This parameter accepts strings or string arrays, enabling you to test multiple hosts simultaneously.
Harnessing the ‘-ComputerName’ Parameter:
[System.Collections.ArrayList]$testArray = @()
Add hosts to the array:
$testArray.Add('192.168.1.1')
$testArray.Add('google.com')
$testArray.Add('qwertyuiop.asdf')
To prevent index output, pipe the ‘Add’ method to ‘Out-Null’:
$testArray.Add('yahoo.com') | Out-Null
To display array values, use:
$testArray
Execute ‘Test-Connection’ with your array:
Test-Connection -ComputerName $testArray
Adding Conditional Logic:
You can use ‘Test-Connection’ within conditional statements, such as:
if (Test-Connection Google.com) {Write-Host "Success!"}
Customizing Your PowerShell Environment
Customize Your Environment Appearance
Your PowerShell environment doesn’t have to be dull and monotonous. With a few simple steps, you can tailor it to your preferences:
- Open PowerShell Console: Begin by opening your PowerShell console. You can do this by searching for “PowerShell” in the Windows search bar or by pressing Windows Key + X and selecting “Windows Terminal” or “Windows PowerShell.”;
- Access Properties: Once your console is open, right-click on the title bar at the top of the window. This will reveal a menu with various options;
- Select Properties: Click on “Properties” from the menu to access the customization options;
- Font Customization: Inside the Properties window, navigate to the “Font” tab. Here, you can adjust the font style and size to your liking. Choose a font that enhances readability during your PowerShell sessions;
- Color Customization: Next, move to the “Colors” tab. This is where you can unleash your creativity. Customize the foreground and background colors to create a visually appealing and distinctive PowerShell console;
- Save Your Settings: Once you’re satisfied with your customizations, make sure to save your settings. You can now enjoy a personalized and visually pleasing PowerShell environment every time you open it.
Customizing Your Profile for a Tailored Experience
- Understanding Profile Files: PowerShell uses profile files to load scripts automatically when you start the console. These profiles can vary depending on the host, but we’ll focus on the user profile across all hosts;
- Check Your Profile: To view your current user profile for all hosts, use the $profile.CurrentUserAllHosts command. It will provide you with the path to your profile script;
- Create the Profile: If your profile doesn’t exist yet, you can create it using the following commands;
- New-Item -Path C:\Users\<YourUsername>\Documents\ -ItemType Directory -Name WindowsPowerShell;
- New-Item -Path C:\Users\<YourUsername>\Documents\WindowsPowerShell\ -ItemType File -Name profile.ps1;
- Replace <YourUsername> with your actual Windows username.
New-Item -Path "$((Get-ChildItem ENV:\UserProfile).Value)\Documents\" -ItemType Directory -Name WindowsPowerShell
New-Item -Path "$((Get-ChildItem
Edit Your Profile: To open and edit your profile file, use the Start-Process cmdlet:
Start-Process $profile.CurrentUserAllHosts
Customize Your Profile Script: Now, you can add custom code to your profile.ps1 file. Here’s an example to get you started:
$foregroundColor = 'white'
$time = Get-Date
$psVersion = $host.Version.Major
$curUser = (Get-ChildItem Env:\USERNAME).Value
$curComp = (Get-ChildItem Env:\COMPUTERNAME).Value
# Customized welcome message
Write-Host "Greetings, $curUser!" -foregroundColor $foregroundColor
Write-Host "It is: $($time.ToLongDateString())"
Write-Host "You're running PowerShell version: $psVersion" -foregroundColor Green
Write-Host "Your computer name is: $curComp" -foregroundColor Green
Write-Host "Happy scripting!" `n
# Customized prompt function
function Prompt {
$curtime = Get-Date
Write-Host -NoNewLine "p" -foregroundColor $foregroundColor
Write-Host -NoNewLine "$" -foregroundColor Green
Write-Host -NoNewLine "[" -foregroundColor Yellow
Write-Host -NoNewLine ("{0}" -f (Get-Date)) -foregroundColor $foregroundColor
Write-Host -NoNewLine "]" -foregroundColor Yellow
Write-Host -NoNewLine ">" -foregroundColor Red
$host.UI.RawUI.WindowTitle = "PS >> User: $curUser >> Current DIR: $((Get-Location).Path)"
Return " "
}
Save and Restart: Once you’ve added your customizations, save the profile.ps1 file and close your PowerShell console. Reopen it to see the changes take effect.
Conclusion
Now, every time you use PowerShell, your customized profile script will enhance your experience by displaying personalized greetings, information, and an eye-catching prompt. Your PowerShell environment is uniquely yours, reflecting your style and preferences. Enjoy scripting in style!