Method invocation failed because [System.Management.Automation.PSObject] doesn’t contain a method named ‘op_Addition’.

Sometimes you can get the following PowerShell error:

Method invocation failed because [System.Management.Automation.PSObject] doesn’t contain a method named ‘op_Addition’. 

Example:

$Update = $Searcher.QueryHistory(0, $historyCount) | Select-Object Title,Date
foreach ($update in $updates)
{  
    $obj | Add-member -Name "Server" -Membertype "Noteproperty" -Value $Server
    $obj | Add-member -Name "Installation Date" -Membertype "Noteproperty" -Value $Update.Date[0]
    $Results += $obj
}

$Results need to be a collection of $obj objects, not another object identical to $obj. So If you want to add PSObjects to a PSObject as a collection, use the following code:

$Results = @()
$Update = $Searcher.QueryHistory(0, $historyCount) | Select-Object Title,Date
foreach ($update in $updates)
{  
    $obj | Add-member -Name "Server" -Membertype "Noteproperty" -Value $Server
    $obj | Add-member -Name "Installation Date" -Membertype "Noteproperty" -Value $Update.Date[0]
    $Results += $obj
}

 

Thanks for reading! You can follow me on Twitter @PrigentNico

About Nicolas 282 Articles
I work as an IT Production Manager, based in Paris (France) with a primary focus on Microsoft technologies. I have 10 years experience in administering Windows Servers. . I am a Microsoft MVP for Cloud & Datacenter Management. I also received the PowerShell Hero 2016 award by PowerShell.0rg. And finally, I am "MCSE: Cloud Platform and Infrastructure", "MCSA: Windows Servers", "Administering & Deploying SCCM", and CheckPoint CCSA certified.