PowerTip: Read Only and Constant Variables

PowerTip: Read Only and Constant Variables

  • Comments 1
  • Likes

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.

 

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • 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