Introduction to the Windows PowerShell Backtick Operator `
It has to be said that if you blink, then you will miss the ` backtick
operator. However, it would be a pity if did, because backtick allows you to word-wrap PowerShell commands.
Incidentally, some people call this the grave key.
When you write code for any scripting language there comes a time when you want the command to wrap onto the next line. PowerShell, along with most languages, regards the end-of-line character as
the end of that command. Consequently, a new line means the start of a new command. Thus we have established the need for a command to tell PowerShell that this command wraps to the next line -
enter the tiny backtick `.
On my
UK keyboard the backtick is on the
top row next to '1' key. It's the key above the Tab and below the Esc key. My key has three symbols, ` ¬ ¦ All you need to get the backtick is press the key on its own
without holding down the shift or the Alt key.
Any doubt about which is the backtick key, hold down the Alt and press
these four numbers on the number pad: 0096, only now let go of the Alt key.
As you can see, unless I use the smallest font, it won't all fit on one line, consequently we need to tell PowerShell to word-wrap. More importantly, most script editors issue an end-of-line
marker before they reach 86 characters.
Challenge: There is a ` backtick after ServiceType, but can you spot a second backtick?
It is important to distinguish the primary use of the backtick, on its own `, and its secondary use as an escape character, for example, backtick with
`n or `t . Let me explain with an example.
2a) Write-host "Heading Sub Heading"
Problem: undesired result
Heading Sub Heading
Solution: Add the crucial `n
2b) Write-host "Heading `nSub Heading"
Result: Desired result achieved
Heading Sub Heading
Note 1: Remember that the escape family `n, `r and `t work within "text" rather than within command statements.
The Engineer's Toolset v10 provides a
comprehensive console of utilities for troubleshooting computer problems. Guy says
it helps me monitor what's occurring on the network, and the tools
teaches me more about how the system literally operates.
There are so many good gadgets, it's like having free rein of a
sweetshop. Thankfully the utilities are displayed logically: monitoring, discovery, diagnostic, and Cisco tools.
Download your copy of the Engineer's Toolset v 10
Take the time to seek out the `backtick key. One day it will help you to word-wrap your commands. There may also be work for the rest of the
PowerShell backtick family, for example `t to align an output
column with a tab.
If you see an error of any kind, do let me know. Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.
*
Guy
Recommends: Orion's NPM - Network Performance Monitor
Orion's performance monitor is designed for detecting network outages.
A network-centric
view make it easy to see what's working, and what needs your attention.
This utility guides you through troubleshooting by indicating whether the
root cause is faulty equipment or resource overload.