PowerShell : resolving error – Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named ‘op_Addition’
![Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.](https://i0.wp.com/knowledge-junction.in/wp-content/uploads/2024/06/fig1.png?fit=944%2C103&ssl=1)
Hi All,
Greetings for the day!!!
Today, a new issue and solution ! This is common or simple issue, but since it took a bit time to solve, I thought to share it.
Issue – Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named ‘op_Addition’
Details
- I have written a PowerShell script to get all apps installed on my site collection.
- I am preparing array objects with app values which I want to export to CSV file.
- Below is sample code:
#preparing PowerShell array object to hold the app instance data
$AppData += New-Object PSObject -Property @{
'App ID' = $appTile.AppId
'App Source' = $appTile.AppSource
'App Status' = $appTile.AppStatus
'App Type' = $appTile.AppType
'App Title' = $appTile.Title -join ""
}#$AppData
#writing app data to CSV file
$AppData | Out-File $allApps_CSV -Append
Issue
- While executing the PowerShell script, I am getting the following error:
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named ‘op_Addition’.
At C:\Prasham\Articles\PowerShell\getallappsinstalled_V1_Kj.ps1:23 char:5
- $AppData += New-Object PSObject -Property @{
~~~~~~~~~~~~- CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
- FullyQualifiedErrorId : MethodNotFound
![Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.](https://i0.wp.com/knowledge-junction.in/wp-content/uploads/2024/06/fig1.png?resize=944%2C103&ssl=1)
Solution / Cause of an error
- It seems like a simple solution. But from the error, it was not easily understood.
- The cause of an issue is that the array object which we are using is not declared. We need to declare the array object as
#result array declaration
$AppData = @()
- As I declared the array, script executed like a charm.
HAPPY SHARING !!! HAPPY LEARNING!!! HAVE a FANTASTIC TIME AHEAD !!!

You must be logged in to post a comment.