Q. Can I declare constants in Windows PowerShell?

To declare constants, you use the New-Variable cmdlet. It includes a switch that lets you define the new variable as a constant, meaning its value can't be changed.

Don Jones

June 30, 2010

1 Min Read
Plane flying across blue sky with cloud trail

A. To declare constants, you use the New-Variable cmdlet. It includes a switch that lets you define the new variable as a constant, meaning its value can't be changed. (I'll make you run

Help New-Variable

to see which one.) Note that all variables are discarded when their scope is destroyed (such as when a script finishes running).

Do you have a Windows PowerShell question? Find more PowerShell FAQs, articles, and other resources at windowsitpro.com/go/DonJonesPowerShell.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like