Powershell: Cannot overwrite variable Host because it is read-only or constant

I got the following error while executing my powershell script.

Cannot overwrite variable host because it is read-only or constant.
At line:1 char:1

  • ~~~~~~~~~~~~~~~~~
    • CategoryInfo : WriteError: (host:String) [], SessionStateUnauthorizedAccessException
    • FullyQualifiedErrorId : VariableNotWritable

$host is a reserved word in powershell. So it worked after replacing $host with $hostname

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top