When I type the following code in a PowerShell console window (version 5.1) it works fine:
$locked = @()
$locked = Search-ADAccount -LockedOut
But when I run it in PowerShell Studio 2024 I get:
ERROR: Method invocation failed because [Microsoft.ActiveDirectory.Management.ADAccount] does not contain a method named 'op_Addition'.
Unlock-Backup.ps1 (21, 2): ERROR: At Line: 21 char: 2
ERROR: + $locked = Search-ADAccount -LockedOut
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
ERROR: + FullyQualifiedErrorId : MethodNotFound
Any idea what I'm doing wrong?
does not contain a method named 'op_Addition'
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This forum is a space to discuss coding in PowerShell, and technical issues related to development.
- Question about a licensed SAPIEN product? Post here: Product Support for Registered Users
- Question about a trial SAPIEN product? Post here: Former and Future Customers - Questions
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This forum is a space to discuss coding in PowerShell, and technical issues related to development.
- Question about a licensed SAPIEN product? Post here: Product Support for Registered Users
- Question about a trial SAPIEN product? Post here: Former and Future Customers - Questions
- Alexander Riedel
- Posts: 8601
- Last visit: Wed Dec 11, 2024 10:07 am
- Been upvoted: 43 times
Re: does not contain a method named 'op_Addition'
This might help:
https://community.spiceworks.com/t/how- ... r/950539/4
It seems this happens if you attempt to fill or append an array from an empty object.
https://community.spiceworks.com/t/how- ... r/950539/4
It seems this happens if you attempt to fill or append an array from an empty object.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: does not contain a method named 'op_Addition'
Thankyou for that.
Changed it to
and it works without ever displaying "Error".
It works, but I don't understand how
Changed it to
- try
- {
- $locked = (Search-ADAccount -LockedOut)
- }
- catch
- {
- Write-Host "Error"
- }
It works, but I don't understand how
-
- Posts: 2
- Last visit: Sun Dec 01, 2024 10:48 pm
Re: does not contain a method named 'op_Addition'
The issue arises because in some contexts, $locked = @() creates an empty array, and PowerShell expects op_Addition to append results to it. This works fine in the standard console but behaves differently in PowerShell Studio, likely due to the execution environment interpreting the variable differently.