79308429

Date: 2024-12-25 23:23:23
Score: 2
Natty:
Report link

In answer by @veefu statement

You can’t supply a type when you use New-Variable so if you need a read only or constant variable then create it as shown above then use Set-Variable to make it read only or constant.

Its exactly the opposite - you can't modify Constant option after you created variable. New-Variable command allows to set options. Set-Variable allows to set options, but doesn't allow to set option - Constant.

This is clearly visible in New-Variable documentation: PowerShell New-Variable [-Option ] from Documentation: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/new-variable?view=powershell-5.1#-option

Also none of the above mentioned methods work in Powershell except .NET method. They are all - strings in result, when I use GetType() and Attributes property of variable never gets populated.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • User mentioned (1): @veefu
  • Low reputation (1):
Posted by: Zedarc7