|
Guy recommends : View the effective permissions for a folder or shared drive. Free download try it now! |
Windows PowerShell QuotesIntroduction to Windows PowerShell QuotesDid you ever use a traditional single-bladed screwdriver on a square 'Philips' head? Sometimes you get away with it, but sooner or later you will literally "screw up" - well it's the same with PowerShell's quotes. Topics for PowerShell Quotes
♣ Introduction to the right sort of PowerShell quotation markIn Windows PowerShell, there are two types of quotes 'single speech marks' and "double speech marks"; each has a particular meaning and significance. The first point is that merely because you use a string, PowerShell does not require any sort of quote. That said, there are times when you will need not only quotes, but also the right sort of quote, for example: # PowerShell quotes needed The above command draws an error message, something about a parameter called and. Fortunately, quotes will solve the problem thus: Set-Location "c:\ documents and settings" Either single or double quotes work in this instance, and you may deduce that they will always be interchangeable - wrong. Take the time to understand the different role for 'single quotes' and "double quotes". Example 1 PowerShell 'Single Quote'Call me paranoid, but when I say 'Single Quote', I am talking about the key sandwiched between the semi-colon and the hash # key. This key is also known as the Apostrophe and corresponds to ASCII 039 in decimal. # PowerShell Single Quotes We have a problem, the above command does not expand the variable $Days into the number 7. What happens instead is we get the literal: There are $Days in a week. Let us see what happens with double quotes in example 2. Example 2 PowerShell "Double Quotes"Double quotes are required in situations where you need to expand variables. This is also known as variable substitution, and it only happens if you employ double quotes. # Note: "Double quotes for $Days" In Example 2 PowerShell expands the command, it switches to what I call mega clever mode, and realizes that I intended $Days to be a variable and not a literal word. SolarWinds Firewall Browser
|
||||
Custom Search
|
Guy Recommends: WMI Monitor for Powershell
|
|
Author: Guy Thomas Copyright © 1999-2013 Computer Performance LTD All rights reserved. Please report a broken link, or an error to: | |