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}
#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: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
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".