Posted on Leave a comment

Variabel read-only?

Today I stumbled upon the error "Variable $ False cannot be changed because it is readonly" in Powershell. The faulty code is hidden here:

param($neuerBenutzer, $verzeichnis, $zugriffsrechte, $testModus=$False, $behalteStandard=$True)

The problem wasn't the code, but the order. In this case, Param belongs to the whole script. So it has to be at the beginning of the code.

The error appears if you have cls in front of param, for example, or maybe an add-in is loaded. Just change the order and it'll work again.