![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Is it possible to create a Constant variable? As the subject says, is it possible to create a constant variable? I was able to set "ReadOnly" option for variables (that i actually wanted to declare as constants) but setting the variable option to "Constant" complains that I need to declare a variable as a constant during creation time of a variable [^_^]PS[167]>$a = "constant string" [^_^]PS[168]>(gi a).options = "Constant" Exception setting "Options": "Existing variable a cannot be made constant. Variables can be made constant only at creat ion time." At line:1 char:8 + (gi a).o <<<< ptions = "Constant" Is there a special keyword to create a constant variable? or is creating a constant available only through Cmdlets in the current version of PowerShell? ==================== Sung M Kim Please don''t bother me with spam... |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Is it possible to create a Constant variable? dance2die wrote: > As the subject says, is it possible to create a constant variable? Yes, use the new-variable command. % new-variable -Option Constant varName "value" % $varName value % $varName = 5 Cannot overwrite variable varName because it is read-only or constant. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Is it possible to create a Constant variable? "Adam Milazzo" wrote: > % new-variable -Option Constant varName "value" > % $varName > value > % $varName = 5 > Cannot overwrite variable varName because it is read-only or constant. > i have overlooked "*-Variable" cmdlets... Thank you for the tips there, Adam ![]() ==================== Sung M Kim Please don''t bother me with spam... |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Is it possible to create a Constant variable? But that does involve using a cmdlet. ![]() "dance2die" <dance2die@discussions.microsoft.com> wrote in message news:79EBC508-8A7F-4502-AEE2-DF51252CEC25@microsoft.com... > "Adam Milazzo" wrote: >> % new-variable -Option Constant varName "value" >> % $varName >> value >> % $varName = 5 >> Cannot overwrite variable varName because it is read-only or constant. >> > > > i have overlooked "*-Variable" cmdlets... > Thank you for the tips there, Adam ![]() > > ==================== > Sung M Kim > > Please don''t bother me with spam... > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Is it possible to create a Constant variable? Alex K. Angelopoulos [MVP] wrote: > But that does involve using a cmdlet. ![]() I think he meant "Is the ability to create constant variables limited to Cmdlets?" And I guess it is, but thankfully there's a Cmdlet that exposes the ability to the shell. :-) |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Is it possible to create a Constant variable? "Alex K. Angelopoulos [MVP]" wrote: > But that does involve using a cmdlet. ![]() "dance2die" wrote: > Cmdlets in the current version of PowerShell? Ah, by the above statement, hmm i meant creating a custom cmdlet in .NET I should have been more elaborate on describing what I really wanted to accomplish. Sorry about the confusion there~==================== Sung M Kim Please don''t bother me with spam... > "dance2die" <dance2die@discussions.microsoft.com> wrote in message > news:79EBC508-8A7F-4502-AEE2-DF51252CEC25@microsoft.com... > > "Adam Milazzo" wrote: > >> % new-variable -Option Constant varName "value" > >> % $varName > >> value > >> % $varName = 5 > >> Cannot overwrite variable varName because it is read-only or constant. > >> > > > > > > i have overlooked "*-Variable" cmdlets... > > Thank you for the tips there, Adam ![]() > > > > ==================== > > Sung M Kim > > > > Please don''t bother me with spam... > > > > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| dynamically create variable? | PowerShell | |||
| Vista Explorer Create New Item Not Visible on Create - Bug or Feature??? | Vista General | |||
| how to assign values to array and how to create array via variable | PowerShell | |||
| How can I ensure that a variable is a built-in powershell variable? | PowerShell | |||
| How To: Create Dynamic Variable Names in Scripts | PowerShell | |||