Use of Constants
Constants in Windows PowerShell are like variables with two important exceptions: Their value never changes, and they cannot be deleted. Constants are created by using the Set-Variable cmdlet and specifying the -option argument to be equal to constant.
Tip
When referring to a constant in the body of the script, you must preface it with the dollar sign—just like any other variable. However, when creating the constant (or even a variable) by using the Set-Variable cmdlet, as you specify the name argument you don't include a dollar sign.
In the GetHardDiskDetails.ps1 script that follows, there is a constant named $intDriveType with a value of 3 assigned. This constant is used because the Win32_LogicalDisk WMI class uses a value of 3 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access