I have a Powershell Script which detects if a virtual Server has dynamic Memory enabled. Everytime i execute my Script the error ReadOnly property appers. Here is the error from PowerShell:
'DynamicMemoryEnabled' is a ReadOnly property.
At C:\Path\to\Script.ps1:131 char:16
+             if($VM.DynamicMemoryEnabled = $false){
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException
This is my Script:
# Get virtual machines
$VMselection = Get-SCVirtualMachine | Where-Object {$_.Name -like "$searchVM"}
$VMs = $VMselection
#Start foreach-Schleife
foreach($VM in $VMs){
            if($VM.DynamicMemoryEnabled = $false){
                $ProcessorCount = $VM.CPUCount
                $StaticMemory = $VM.Memory
                $MemoryConfiguration = $VM.DynamicMemoryEnabled
                $MemorySize = $StaticMemory / "1024"
                # Format for Output
                $OutputFormat = "{0}c / {1}G{2}"
                if($MemoryConfiguration -eq $true){
                    $MemoryUnit = "d"
                }
                else{
                    $MemoryUnit = "s"
                }
                # Result Output
                $VMName = $VM.Name
                $Output = $OutputFormat -f $ProcessorCount, $MemorySize, $MemoryUnit
                [PSCustomObject]@{
                    Servername = $VMName
                    "CPU / RAM" = $Output
                } | Out-Null
            }
            else{
                $ProcessorCount = $VM.CPUCount
                $DynamicMemory = $VM.DynamicMemoryMaximumMB
                $MemoryConfiguration = $VM.DynamicMemoryEnabled
                $MemorySize = $DynamicMemory / "1024"
                # Format for Output
                $OutputFormat = "{0}c / {1}G{2}"
                if($MemoryConfiguration -eq $true){
                    $MemoryUnit = "d"
                }
                else{
                    $MemoryUnit = "s"
                }
                # Result Output
                $VMName = $VM.Name
                $Output = $OutputFormat -f $ProcessorCount, $MemorySize, $MemoryUnit
                [PSCustomObject]@{
                    Servername = $VMName
                    "CPU / RAM" = $Output
                } | Out-Null
            }
PS: Its just a snippet of my Script. These values are later on displayed into a DataGridView.
 
    