PS C:\> $var = 'What does $var contain ' PS C:\> $var What does $var contain in VB.NET

Encoder Data Matrix ECC200 in VB.NET PS C:\> $var = 'What does $var contain ' PS C:\> $var What does $var contain

PS C:\> $var = 'What does $var contain ' PS C:\> $var What does $var contain
Paint ECC200 In VB.NET
Using Barcode maker for VS .NET Control to generate, create Data Matrix ECC200 image in Visual Studio .NET applications.
www.OnBarcode.com
Data Matrix 2d Barcode Decoder In VB.NET
Using Barcode reader for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Here, you can see that the $var within single quotes is treated as a literal. In double quotation marks, however, that s not the case. Check out this trick:
PDF 417 Printer In VB.NET
Using Barcode generation for Visual Studio .NET Control to generate, create PDF-417 2d barcode image in .NET applications.
www.OnBarcode.com
EAN13 Creation In Visual Basic .NET
Using Barcode drawer for .NET framework Control to generate, create GS1 - 13 image in .NET framework applications.
www.OnBarcode.com
PS C:\> $computername = 'SERVER-R2' PS C:\> $phrase = "The computer name is $computername" PS C:\> $phrase The computer name is SERVER-R2
Create Data Matrix 2d Barcode In VB.NET
Using Barcode encoder for VS .NET Control to generate, create ECC200 image in VS .NET applications.
www.OnBarcode.com
Generating QR Code In VB.NET
Using Barcode drawer for .NET framework Control to generate, create Denso QR Bar Code image in .NET framework applications.
www.OnBarcode.com
I started by storing SERVER-R2 in the variable $computername. Next, I stored "The computer name is $computername" in the variable $phrase. When I did so, I used double quotes. PowerShell will automatically seek out dollar signs within double quotes, and
Create UCC.EAN - 128 In VB.NET
Using Barcode encoder for .NET Control to generate, create EAN / UCC - 14 image in .NET applications.
www.OnBarcode.com
Encode ISSN - 10 In VB.NET
Using Barcode generator for .NET framework Control to generate, create ISSN image in Visual Studio .NET applications.
www.OnBarcode.com
Fun tricks with quotes
DataMatrix Drawer In C#
Using Barcode generation for VS .NET Control to generate, create DataMatrix image in VS .NET applications.
www.OnBarcode.com
Painting DataMatrix In Visual Basic .NET
Using Barcode creation for Visual Studio .NET Control to generate, create Data Matrix ECC200 image in .NET framework applications.
www.OnBarcode.com
replace any variables it finds with their contents. So when I displayed the contents of $phrase, $computername was replaced with SERVER-R2, the contents of the variable. This replacement action only happens when the string is initially parsed by the shell. So, right now, $phrase contains "The computer name is SERVER-R2" it doesn t contain the "$computername" string. I can test that by trying to change the contents of $computername, and seeing if $phrase updates itself:
Draw Code 39 In None
Using Barcode generator for Microsoft Excel Control to generate, create Code 3 of 9 image in Excel applications.
www.OnBarcode.com
Code 128A Encoder In Visual Studio .NET
Using Barcode printer for Reporting Service Control to generate, create Code 128A image in Reporting Service applications.
www.OnBarcode.com
PS C:\> $computername = 'SERVER1' PS C:\> $phrase The computer name is SERVER-R2
Barcode Reader In .NET Framework
Using Barcode Control SDK for ASP.NET Control to generate, create, read, scan barcode image in ASP.NET applications.
www.OnBarcode.com
Reading Barcode In .NET
Using Barcode decoder for .NET framework Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
The $phrase variable stayed the same. Another facet of this double quotes trick is the PowerShell escape character. This character is the backtick (`), and on a U.S. keyboard it s located on one of the upperleft keys, usually below the Escape key and usually on the same key as the tilde (~) character. The problem is that, in some fonts, it s practically indistinguishable from a single quote. In fact, I usually configure my shell to use the Consolas font, because it makes it a little bit easier to distinguish the backtick than the Lucida Console or Raster font. Click the control box in the upper-left corner of your PowerShell window, and select Properties. On the Font tab, select the Consolas font. Click OK, and then type a single quote and a backtick so that you can see the difference between these characters. Figure 15.1 shows what it looks like on my system. Can t see the difference I barely can, either, even when using a pretty large font size. It s a tough distinction, but make sure you re comfortable distinguishing between them in whatever font face and size you select.
Reading Code 128 In VB.NET
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
UCC.EAN - 128 Creator In Visual C#.NET
Using Barcode generation for VS .NET Control to generate, create EAN / UCC - 14 image in VS .NET applications.
www.OnBarcode.com
TRY IT NOW
Print Barcode In VS .NET
Using Barcode printer for Visual Studio .NET Control to generate, create Barcode image in .NET applications.
www.OnBarcode.com
Code 128 Code Set A Generator In None
Using Barcode generation for Font Control to generate, create Code 128B image in Font applications.
www.OnBarcode.com
Figure 15.1 Setting a font that makes it easier to distinguish the backtick character from the single quote
Code 3/9 Generator In Visual Studio .NET
Using Barcode encoder for Reporting Service Control to generate, create Code 3/9 image in Reporting Service applications.
www.OnBarcode.com
EAN 13 Creation In Objective-C
Using Barcode creation for iPhone Control to generate, create UPC - 13 image in iPhone applications.
www.OnBarcode.com
Variables: a place to store your stuff
So what does this escape character do It removes whatever special meaning might be associated with the character after it, or in some cases, it adds special meaning to the following character. Here s an example of this first usage:
PS C:\> $computername = 'SERVER-R2' PS C:\> $phrase = "`$computername contains $computername" PS C:\> $phrase $computername contains SERVER-R2
When I assigned the string to $phrase, I used $computername twice. The first time, I preceded the dollar sign with a backtick. Doing so took away the dollar sign s special meaning as a variable indicator, and made it a literal dollar sign. You can see in the final output, on the last line, that $computername was stored in the variable. I didn t use the backtick the second time, so $computername was replaced with the contents of that variable. Now, here s an example of the second way a backtick can work:
PS C:\> $phrase = "`$computername`ncontains`n$computername" PS C:\> $phrase $computername contains SERVER-R2
Look carefully, and you ll notice two `n in the phrase one after the first $computername and one after contains. In this example, the backtick is adding a special meaning. Normally, an n is just a letter, but with the backtick in front of it, it becomes a carriage return and line feed (think n for new line). Run help about_escape for more information, including a list of other special escape characters. You can, for example, use an escaped t to insert a tab, or an escaped a to make your computer beep (think a for alert).
Copyright © OnBarcode.com . All rights reserved.