0

Set-Variable helpText -option Constant -value "somevalue"

Set-Variable : Cannot overwrite variable helpText because it is read-only or constant.

I am getting the below error in power shell. Can some one let me know what I am missing here.

Thanks in Advance

TJK
  • 441
  • 4
  • 11
  • 27
  • If it is constant then it can't be changed. That is kinda what constant means. – EBGreen May 10 '13 at 17:53
  • Even if I remove -option Constant from the code, I am getting the same error. – TJK May 10 '13 at 18:12
  • 1
    My suspicion is that $helpText is being set somewhere else. That or you have run the same code before (which would have made it a constant) in the same session. – EBGreen May 10 '13 at 18:17

2 Answers2

1

Constant variables cannot be deleted and its properties cannot be changed.

To delete it, you can only close the current session and start over again.

Consider using the ReadOnly option instead. Then you can overwrite it with -Force switch.

Davor Josipovic
  • 5,296
  • 1
  • 39
  • 57
-2

As it allready said in the comments to the question, constant variables cannot be changed while runtime.

Declare the variable as following, than you can override it with -Force

Set-Variable helpText "somevalue" -Option ReadOnly
Solaflex
  • 1,382
  • 1
  • 13
  • 24