Reader small image

You're reading from  Mastering PowerShell Scripting - Fourth Edition

Product typeBook
Published inJun 2021
PublisherPackt
ISBN-139781800206540
Edition4th Edition
Right arrow
Author (1)
Chris Dent
Chris Dent
author image
Chris Dent

Chris Dent is an automation specialist with deep expertise in the PowerShell language. Chris is often found answering questions about PowerShell in both the UK and virtual PowerShell user groups. Chris has been developing in PowerShell since 2007 and has released several modules over the years.
Read more about Chris Dent

Right arrow

Naming and creating variables

Variables in PowerShell are preceded by the dollar symbol ($), for example:

$MyVariable

The name of a variable may contain numbers, letters, and underscores. For example, each of the following is a valid name:

$123 
$x 
$my_variable 
$variable 
$varIABle 
$Path_To_File 

Variables are frequently written in either camel case or Pascal case. For example:

  • $myVariable is camel case
  • $MyVariable is Pascal case

PowerShell does not enforce a naming convention, nor does it consistently use a convention in the automatic variables.

One of the most commonly accepted practices is that variables used as parameters must use Pascal case. Variables used only within a script or a function must use camel case.

I suggest making your variable names meaningful so that when you revisit your script after a long break, you can identify its purpose. I recommend choosing and maintaining a consistent style in your own code...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Mastering PowerShell Scripting - Fourth Edition
Published in: Jun 2021Publisher: PacktISBN-13: 9781800206540

Author (1)

author image
Chris Dent

Chris Dent is an automation specialist with deep expertise in the PowerShell language. Chris is often found answering questions about PowerShell in both the UK and virtual PowerShell user groups. Chris has been developing in PowerShell since 2007 and has released several modules over the years.
Read more about Chris Dent