I would like to declare some integer constants in Powershell.
Is there any good way to do that?
I would like to declare some integer constants in Powershell.
Is there any good way to do that?
Use -option Constant
with the Set-Variable
cmdlet:
Set-Variable myvar -option Constant -value 100
Now $myvar
has a constant value of 100 and cannot be modified.
Use
Set-Variable test -option Constant -value 100
or
Set-Variable test -option ReadOnly -value 100
The difference between "Constant" and "ReadOnly" is that a read-only variable can be removed (and then re-created) via
Remove-Variable test -Force
whereas a constant variable can't be removed (even with -Force).
See this TechNet article for more details.