question

AintGotNoTime-6052 avatar image
0 Votes"
AintGotNoTime-6052 asked AintGotNoTime-6052 commented

PSObject does not contain op_addition

Don't know why I am getting this error as it should not even be getting into the Catch statement as all the accounts I looked up in AD where successful, so I dont know why it would through the error on the catch. There are accounts, and they work, but catch still throws the error on the addition of any bad accounts.

Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At D:\Apps\OnboardMailboxesV4.0.ps1:111 char:21
+ $BadOnboarded += $acct
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound


 #Grab the Session string and put that back into headers
     $authentication = Invoke-RestMethod -Method 'Post' -Uri $authUri -Body $body
    
    
 #Create the headers agian to get rid of the JSON format for importing accounts
     $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
     $headers.Add("Authorization", $authentication)
    
 #Add Accounts to Vault
     foreach($acct in $DomainacctArray)
         {
                
             $acctbody = @{
                 "address"= $acct.address;
                 "userName"= $acct.userName;
                 "platformId"= $acct.platformId;
                 "safeName"= $acct.safeName;
                 "secret"= $acct.secret}
    
             try{
                     #Insert account into Vault 
                    Write-Host $acctbody.Values
                    # $insertacct = Invoke-RestMethod -Method Post -Uri $acctUri -Headers $headers -Body $acctbody
                     $countrecord += 1
                     #$rebuildUri = """
                     #$response = Invoke-RestMethod -Uri $rebuildUri  -Method 'POST' -Headers $headers
                     $Onboarded += $acct
             }
             catch{
                     $BadOnboarded += $acct
                     $countBadRecord += 1
             }
    
          }  


windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered AintGotNoTime-6052 commented

Without the entire script it's hard to say where the error originates, but it would be my guess that somewhere else in your script you set the value of the variable $BadOnboarded to be something other than an array.

The error says that it has a type of "System.Management.Automation.PSObject".

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yep ok, I forgot to call it out to a array upfront and its fixed. thanks

0 Votes 0 ·