PowerShell – Command Line – Differences between double-quote and single-quote

Background

Want to quickly touch on one of the differences between how PowerShell processes double and single quotes.

 

Scenario

Command Line

Double-Quotes Versus Single Quotes

Syntax


pwsh -Command <command>

Sample

Double Quotes

Sample

pwsh -Command "$PSVersionTable"

Output
Output – Image

Output – Text

>pwsh -Command "$PSVersionTable"
>

Explanation

Issuing the command ” pwsh -Command “$PSVersionTable” ” returns an empty output

 

Single Quotes

Sample

pwsh -Command '$PSVersionTable'

Output
Output – Image

Output – Text

>pwsh -Command '$PSVersionTable'

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Linux 4.18.0-240.1.1.el8_3.x86_64 #1 SMP Thu Nov 19 17:20:08 UTC 2020
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

>

Explanation
  1. PSVersion:- 7.1.3
  2. PSEdition:- Core
  3. OS:- Linux
  4. Platform:- Unix

 

Summary

I really do not want to get into the reason for the technical differences in this post.

But, if you find yourself trying out simple commands, yet PowerShell is throwing them back at you, please go back and look at your interface or script and see whether you should be using double or single quotes.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s