PowerShell Special Characters

As in every programming and scripting language, in PowerShell there are special characters that you can use to represent characters, that we are not able to find in the standard set. In this tutorials we will see those PowerShell special Characters and what is their use.

All special characters in PowerShell start with backtick ( ` ). You can use the special characters only within double quotes ( " " ). If they are used otherwise, they will not be interpreted to the desired one. First of all we will see the list of characters and then we will go through it to see more details for each of the special characters. The list is provided by Microsoft.

Special Characters List:

`0 – Null

– Null `a – Alert

– Alert `b – Backspace

– Backspace `e – Escape

– Escape `f – Form Feed

– Form Feed `n – New Line

– New Line `r – Carriage Return

– Carriage Return `t – Horizontal Tab

– Horizontal Tab `u{x} – Unicode Escape Sequence

– Unicode Escape Sequence `v – Vertical Tab

– Vertical Tab --% – Stop Parsing

Null

`0

The null character is presented in PowerShell output as an empty space. It is not the same with $null variable. As per Microsoft, this allows you to use Windows PowerShell to read and process text files that use null characters, such as string termination or record termination indicators.

Alert

`a

The Alert character can send a beep sound to the computer’s speaker. You can use this character to warn the user for an action that he is trying to perform.

[adinserter name=”In Article”]

Backspace

`b

The backspace character will move the cursor 1 character backwards. Although, when we are using backspace on our keyboard, the cursor is moved 1 character back and removes the last character. When you use it in PowerShell it will move only the cursor back by one character. In order to remove the characters also, you need to provide the characters that will replaced those after the cursor. As you can see below when I use on the backspace character and not provide anything, Windows PowerShell output gives me the the same words I provide to it. On the second example, that I provide new characters after the backspace, you can see the the word “World has been replace with “Everyone”.

Example:

Escape

`e

As provided by Microsoft:

The escape character is most commonly used to specify a virtual terminal sequence (ANSI escape sequence) that modifies the color of text and other text attributes such as bolding and underlining. These sequences can also be used for cursor positioning and scrolling. The PowerShell host must support virtual terminal sequences. This can be checked on PowerShell v5 and higher with the boolean property $Host.UI.SupportsVirtualTerminal.

Form Feed

`f

The form feed character (`f) is a print instruction that ejects the current page and continues printing on the next page. This character affects printed documents only; it does not affect screen output.

[adinserter name=”In Article”]

New Line

`n

The new line character inserts a line break immediately after the character and continues the text from that line.

Example:

Carriage Return

`r

The carriage return character will not output any text prior to it. It considers anything prior to it as a different line. As you can see in the example below you can combine it with new line character and then both parts of the text will be provided to output.

Example:

[adinserter name=”In Article”]

Horizontal Tab

`t

The horizontal tab character goes to the next tab and continues the rest of the text from that point. As per Microsoft, the default for Windows PowerShell tab space is 8 spaces.

Example:

Unicode Escape Sequence

`u{x}

As provided by Microsoft:

The Unicode escape sequence allows you to specify any Unicode character by the hexadecimal representation of its code point. This includes Unicode characters above the Basic Multilingual Plane (> 0xFFFF) which includes emoji characters e.g. `u{1F44D} . The Unicode escape sequence requires at least one hex digit and supports up to six hex digits. The maximum hex value for the sequence is 10FFFF.

[adinserter name=”In Article”]

Vertical Tab

`v

The vertical tab character goes to the next vertical tab and continues to write the rest part of the text. It can only affect the document printouts. Nothing will be done on the screen.

Stop Parsing

--%

As provided by Microsoft:

The stop-parsing symbol (–%) prevents Windows PowerShell from interpreting arguments in program calls as Windows PowerShell commands and expressions. Place the stop-parsing symbol after the program name and before program arguments that might cause errors.

Example:

I hope the tutorial about PowerShell Special Characters is helpful.

Please let me know your comments and thoughts.

You feedback is appreciated.

[adinserter name=”In Article”]

Related Links:

[adinserter name=”Matched-Content”]