PowerShell provides several cmdlets for displaying text on the console screen. As you may have guessed, each cmdlet is intended for a specific purpose. In this article, I will introduce four of these cmdlets and demonstrate how to use them.
The first cmdlet is Write-Warning, which is useful when you need to display a warning message to whoever is running the script.
Write-Warning “This is an example warning.”
Console Output 1
You can display custom warning messages by using the Write-Warning cmdlet.
Write-Warning “This is an example warning.” -WarningAction Inquire
Console Output 2
I am trying to get full structure of my project in tree format in powershell.
When I use the command tree
, it only shows directories and subdirectories, but neither files nor hidden folders, such as .git
How can I show files as well?
67 gold badges672 silver badges861 bronze badges
asked Aug 14, 2023 at 19:57
does have an option to include files in the output:
/F
answered Aug 14, 2023 at 20:25
67 gold badges672 silver badges861 bronze badges
Similar to generating custom warning messages, you can also create custom error messages. The cmdlet used for doing so is . Additionally, there’s a separate cmdlet called that allows you to generate an error.
Console Output 3
You can use the Write-Error cmdlet to display a custom error message.
Write-Error “This is an example error.” -Category InvalidOperation
You can see an example of how an error category works in Figure 4. Microsoft provides a list of all the available categories
Console Output 4
You can append a category to an error message.
cmdlet is similar to the Write-Host cmdlet, but with two notable differences.
Firstly, Write-Output exclusively supports plain text. You can’t change the text color or add other effects to the text.
The second difference is the automatic enumeration of objects by the Write-Object cmdlet. However, if you want to treat an array as a single object within pipeline operations, you can use the
Granted, this is a bit of a nonsense example, but it illustrates the idea that the output is treated as an object.
Such an operation would not be allowed with the Write-Host cmdlet.
Admittedly, I can’t seem to recall ever having used the Write-Output cmdlet in a script. While I am sure that the cmdlet has its place, I can’t think of anything that Write-Output can do that can’t be done using Write-Host and variables.
Console Output 5
he NoEnumerate switch allows a collection to be treated as a single item.
cmdlet is the standard command used to display text on the console screen in PowerShell. To use this cmdlet, you simply append the text you want to display. For example:
Write-Host “This text will be displayed on the screen.”
Unlike the Write-Output cmdlet, the Write-Host cmdlet allows you to change both the foreground and the background color of the text. Here’s an example:
Write-Host “White text on a blue background” -Foregroundcolor White -BackgroundColor Blue
Console Output 6
The Write-Host cmdlet supports colorful output.
Unfortunately, Write-Host does not support other text effects such as bold or blinking text. While it was once possible to achieve such effects by embedding various ANSI escape sequences, Microsoft appears to have disabled support for ANSI-based text effects within the PowerShell console. Some ANSI escape sequences, like those for creating a new line or inserting a tab, still work, but those related to text color and attributes (bold, underline, etc.) no longer function.
Different versions of PowerShell have different features and capabilities. So, it is good to know the versions of PowerShell you are using. In this tutorial, I will show you how to check PowerShell version using different methods.
To check your PowerShell version, open PowerShell and type $PSVersionTable.PSVersion to see the version details. Alternatively, you can use Get-Host by typing Get-Host and looking for the Version property, or use Get-Command with (Get-Command powershell).Version. On Windows, you can also check the version in the Registry Editor under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine. For PowerShell Core on Linux or macOS, type pwsh –version in the terminal.
Get the PowerShell version using different methods
Method 1: Using $PSVersionTable
The easiest ways to check your PowerShell version is by using the $PSVersionTable
automatic variable. This variable contains a lot of useful information about your PowerShell environment, including the version.
Here is the command.
$PSVersionTable.PSVersion
You can see the screenshot below. I executed the above command using VS code. It shows me the PowerShell version.

Method 2: Using Get-Host
The Get-Host
cmdlet provides information about the current host program, including the version of PowerShell.
Get-Host
The output is shown in the screenshot below. It provides a lot of information, including the PowerShell version. This time, I executed the script using Windows PowerShell ISE.
Name : Windows PowerShell ISE Host
Version : 5.1.22621.2506
InstanceId : aaa160fc-9465-4e39-84aa-2737f3b88c08
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-IN
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.Host.ISE.ISEOptions
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
Here the Version
property indicates the PowerShell version.

Method 3: Using Get-Command
You can also use the PowerShell Get-Command cmdlets to get the PowerShell version. Below is the complete command.
(Get-Command powershell).Version
Method 4: Checking the Registry (Windows Only)
If you have knowledge about the Windows Registry, you can also check the PowerShell version there.
Here are the steps:
- Press
Win + R
, typeregedit
, and press Enter to open the Registry Editor. - Navigate to the following path:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine
- Look for the
PowerShellVersion
entry, which will display the version.
Method 5: Using PowerShell Core on Linux or macOS
If you are using PowerShell Core on Linux or macOS, you can check the version using the pwsh
command.
Here are the steps:
- Open Terminal.
- Type the following command and press Enter:
pwsh --version
- The terminal will display the PowerShell version:
PowerShell 7.4.0
Conclusion
In this tutorial, I have explained different methods to get the PowerShell version:
- Using $PSVersionTable
- Using Get-Host
- Using Get-Command
- Checking the Registry (Windows Only)
- Using PowerShell Core on Linux or macOS
You may also like:
If you run the same commands every time you launch the PowerShell console, then it’s probably time to customize your PowerShell profile for a smoother scripting experience.
When you develop a profile in PowerShell, you define your settings as a PowerShell script to make the process easier. In this article, learn about the PowerShell profile, how to edit your profile for any PowerShell console — the newer cross-platform PowerShell 7, Windows PowerShell 5.1, Visual Studio (VS) Code and PowerShell Integrated Script Environment (ISE) — and several handy additions for your profile.
What is the PowerShell profile?
The PowerShell profile is a PowerShell script that runs every time you launch PowerShell, except when you use the flag. The PowerShell profile location varies depending on several conditions:
- The version of PowerShell: Windows PowerShell or PowerShell 7?
- Is the profile for all users or the current user?
- Is the profile host application-specific?
- Windows PowerShell: $PSHOME\
- PowerShell 7:
- Windows: $PSHOME\
- Linux: /usr/local/Microsoft/powershell/7/
- macOS: /usr/local/Microsoft/powershell/7/
- Windows PowerShell: $HOME\Documents\WindowsPowerShell\
- PowerShell 7:
- Windows: $HOME\Documents\PowerShell\
- Linux: ~/.config/powershell/
- macOS: ~/.config/powershell/
The directories can have several valid profile files. The difference between the profiles is based on the host application that launches PowerShell. We use ISE and VS Code as examples for hosts:
- All hosts: profile.ps1
- ISE: Microsoft.PowerShellISE_profile.ps1
- VS Code: Microsoft.VSCode_profile.ps1
- All users, all hosts: $PSHOME\profile.ps1
- All users, VS Code: $PSHOME\Microsoft.VSCode_profile.ps1
- Current user, all hosts: $HOME\profile.ps1
- Current user, VS Code: $HOME\Microsoft.VSCode_profile.ps1
If any of those files don’t exist, PowerShell skips that profile.
How to access your PowerShell profile
The easiest way to retrieve the PowerShell profile is through PowerShell itself. You don’t need to remember the profile paths because they are stored in the variable.

$Profile | Get-Member -MemberType NoteProperty

$Profile.AllUsersAllHosts

$Profile.CurrentUserCurrentHost

code $Profile.CurrentUserCurrentHost
How to customize the PowerShell profile
Due to the PowerShell profile’s flexibility, you have a range of customization options to suit how you want PowerShell to work.
Customize your PowerShell prompt
We could dedicate a whole article to this topic and still not cover all the possibilities to modify the PowerShell prompt. If you aren’t familiar with customizing your PowerShell prompt, you can find many examples of cool prompts to see what’s possible. This article covers a basic example.
Function Prompt {
$endChar = '>'
# check if running as admin
If
(([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
$endChar = '#'
}
@"
$PWD
PS$endChar
"@
}
To make this function run every time PowerShell loads, put it in your profile.
How to load a PowerShell module and set defaults
A mistake that I regularly make is using a module that requires authentication before I’ve authenticated. Some of the modules have checks that remind you to authenticate, while others throw a cryptic error. If this problem occurs for a module you use frequently, then consider adding the authentication steps to your profile.
Connect-Graph
$graphUserProps = @(
'BusinessPhones',
'DisplayName',
'GivenName',
'Id',
'Mail',
'PreferredLanguage',
'Surname',
'UserPrincipalName'
)
Get-MgUser -UserId <upn> -Select ($graphUserProps + 'AccountEnabled','UsageLocation')
How to add aliases and argument completers
New-Alias -Name gmu -Value Get-MgUser
However, one of my favorite aliases is for kubectl, the Kubernetes command-line tool for working with clusters. I use the letter as my alias:
New-Alias -Name k -Value kubectl
How to add custom functions to your PowerShell profile
As you develop your PowerShell abilities, you might write more one-off functions to help with your work. But you might not feel the code is worth adding to a module. After you put your code in a source control platform, such as GitHub, then you can use dot sourcing to load the code when running PowerShell:
. C:\path\to\Function.ps1
This is just the start of what is possible. Start thinking about the commands you run frequently, and consider the other ways you can customize your PowerShell profile to make your life easier.
Anthony Howell is an IT expert who is well versed in multiple infrastructure and automation technologies, including PowerShell, DevOps, cloud computing, and the Windows and Linux OSes.
About the Author(s)
Brien Posey is a bestselling technology author, a speaker, and a 20X Microsoft MVP. In addition to his ongoing work in IT, Posey has spent the last several years training as a commercial astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space.