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