PowerTip: Read Only and Constant Variables


Summary: Learn the difference between a read-only variable and a constant.

Question: What is the difference between a read-only variable and a constant?

Answer: A read-only variable is one with content that is read-only. It can, however, be modified by using the Set-Variable cmdlet with the –force parameter. It can also be deleted by using Remove-Variable –force.  A constant variable, however, cannot be deleted, nor can it be modified–even when using the force.

 

Comments (1)

  1. K_Schulte says:

    Hi Ed,

    this is something I knew, but it is also something I always seem to have forgotten,

    if I look at my scripts! I rarely used constants or read-only variables …

    Klaus

Skip to main content