Powershell: Cannot overwrite variable Host because it is read-only or constant
While creating a Powershell script to pull statistic data from ESX hosts I ran into this error message:
Cannot overwrite variable Host because it is read-only or constant.
At line:16 char:8
+ foreach <<<< ($host in $ESXHosts)
+ CategoryInfo : WriteError: (Host:String) [], SessionStateUnauthorizedAccessException
+ FullyQualifiedErrorId : VariableNotWritable
Apparently $Host is a reserved word / Variable in Powershell. Changing the variable name to $ESXHost solved the problem for me.