PowerTip: Mini-Scripting Games 2014 Question 5

PowerTip: Mini-Scripting Games 2014 Question 5

  • Comments 2
  • Likes

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!

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • 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