PowerTip: Mini-Scripting Games 2014 Question 5

Summary: Here is the fifth short-answer question for Mini-Scripting Games 2014.

Hey, Scripting Guy! Question You created a constant variable in your Windows PowerShell console.
           Now when you attempt to delete the variable, you get an error message.
           How can you remove a constant variable?

Hey, Scripting Guy! Answer Answer to be posted next week!

Comments (1)

  1. LOL, make the file read-only, the variable becomes a constant, can’t be removed because it didn’t really exist

    PS C:> ${C:VAR.txt}="This is a constant"
    PS C:> ${C:VAR.txt}
    This is a constant

    #Set File to Read-only and it will make it a const

    PS C:> Get-ChildItem C:VAR.txt | % {$_.IsReadOnly = $True}

    PS C:> ${C:VAR.txt}="This is a different constant"
    Access to the path ‘C:VAR.txt’ is denied.
    At line:1 char:14
    + ${C:VAR.txt} <<<< ="This is a different constant"
    + CategoryInfo : PermissionDenied: (C:VAR.txt:String) [], UnauthorizedAccessException
    + FullyQualifiedErrorId : GetContentWriterUnauthorizedAccessError

    PS C:> ${C:VAR.txt}
    This is a constant

Skip to main content