title: During uninstall third party application from control panel, I am getting this error. You cannot call a method on a null-valued expression PowerShell
body: <p>I am having script to uninstall <strong>Veeam</strong> software from control panel through PowerShell. While during uninstall of last the last Veeam components I am getting below error:</p>
  <pre><code>You Cannot call a method on a null-valued expression PowerShell : line 15 char:1
  + $console.Uninstall()
  + CategoryInfo         : InvalidOperation: (:) [], RuntimeException
  +FullyQualifiedErrorId : InvokeMethodOnNull
  </code></pre>
  <p>I have no idea, Experts help me to fix it. I am waiting for your reply. I have attached my script below.</p>
  <pre><code>function uninstallvm
  {
  $veeamConsole = 'Veeam Backup &amp; Replication Console'
  $objects = Get-WmiObject -Class win32_product
  $veeamComponents = $objects | where {$_.Name -like 'Veeam*' -and $_.Name -ne $veeamConsole}
  foreach ($object in $veeamComponents) {
    Write-Output &quot;Uninstalling $($object.Name)&quot;
    $object.Uninstall()
  }
  Start-Sleep -Seconds 5
  $console = $objects | where {$_.Name -eq $veeamConsole}
  Write-Output &quot;Uninstalling $($console.Name)&quot;
  $console.Uninstall() 
  }
  uninstallvm
  </code></pre>