Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Method failed 'op_Addition'

Closed Thread
 
Thread Tools Display Modes
Old 01-18-2007   #1 (permalink)
Jonathan Kalmes
Guest


 

Method failed 'op_Addition'

Hey all,

I think I've somehow managed to hose smthng but I have no idea what.
I've got a relatively simple script that worked until this morning.
Here's the offending command I'm running within a for-next loop (all one
line):

$ResultCont += ( Get-wmiobject -class exchange_SMTPQueue -Namespace
ROOT\MicrosoftExchangev2 -ComputerName $objItem | Select-Object
VirtualMachine,LinkName,QueueName,MessageCount,Size | Where-Object
-FilterScript {$_.MessageCount -ne 0} )

Here's the error it now generates AFTER the first iteration of the loop:

Method invocation failed because [System.Management.Automation.PSObject]
doesn't contain a method named 'op_Addition'.
At C:\Scripts\ExchQueues.ps1:5 char:16
+ $ResultCont += <<<< ( Get-wmiobject -class exchange_SMTPQueue
-Namespace ROOT\MicrosoftExchangev2 -ComputerName
$objItem | Select-Object
VirtualMachine,LinkName,QueueName,MessageCount,Size | Where-Object
-FilterScript {$_.MessageCo
unt -ne 0} )

It looks to me like PS how now decided that it doesn't like it's own +=
operator. Any ideas what I did to cause this or how I'd go about
restoring it again?

--Jonathan "smthng" Kalmes
http://smthng.info
Old 01-18-2007   #2 (permalink)
Keith Hill [MVP]
Guest


 

Re: Method failed 'op_Addition'

"Jonathan Kalmes" <smthng@smthng.info> wrote in message
news:%23t84Y9xOHHA.3544@TK2MSFTNGP03.phx.gbl...
> Hey all,
>
> I think I've somehow managed to hose smthng but I have no idea what. I've
> got a relatively simple script that worked until this morning. Here's the
> offending command I'm running within a for-next loop (all one line):
>
> $ResultCont += ( Get-wmiobject -class exchange_SMTPQueue -Namespace
> ROOT\MicrosoftExchangev2 -ComputerName $objItem | Select-Object
> VirtualMachine,LinkName,QueueName,MessageCount,Size |
> Where-Object -FilterScript {$_.MessageCount -ne 0} )
>
> Here's the error it now generates AFTER the first iteration of the loop:
>
> Method invocation failed because [System.Management.Automation.PSObject]
> doesn't contain a method named 'op_Addition'.
> At C:\Scripts\ExchQueues.ps1:5 char:16
> + $ResultCont += <<<< ( Get-wmiobject -class
> exchange_SMTPQueue -Namespace ROOT\MicrosoftExchangev2 -ComputerName
> $objItem | Select-Object
> VirtualMachine,LinkName,QueueName,MessageCount,Size |
> Where-Object -FilterScript {$_.MessageCo
> unt -ne 0} )
>
> It looks to me like PS how now decided that it doesn't like it's own +=
> operator. Any ideas what I did to cause this or how I'd go about
> restoring it again?


I would guess that you previously assigned an object of type PSObject to the
variable $ResultCont. Try executing this first before your command above:

$ResultCont = @()

The addition operation it attempts is going to be based on the type of of
variable on the left. In this case, since += is the equivalent of:

$ResultCont = $ResultCont + (....)

It is the type of $ResultCont that dictates the behavior of the + operator.
Not sure how the algorithm works if $ResultCont is non-existant or null but
it seems to use the "type" of the right hand operand in that case.

--
Keith


Old 01-18-2007   #3 (permalink)
Jonathan Kalmes
Guest


 

Re: Method failed 'op_Addition'

Keith Hill [MVP] wrote:
<snip>
> I would guess that you previously assigned an object of type PSObject to the
> variable $ResultCont. Try executing this first before your command above:
>
> $ResultCont = @()


Sweet! You da man! BTW... I hadn't declared or assigned $ResultCont at
all. I assumed it would always be null when starting, which in my case
is true enough that it doesn't really matter. But...

My problem was that the WMI query can return multiple queues on the
first iteration of the loop. If that happens, there are no problems as
the first assignment includes multiple values, so it's automagically
created as an array. The reason it failed today is because I'd cleaned
up our queues and only ONE was found to have messages on the first
iteration. That would cause $ResultCont to be assigned as a simple
string, not an array. Hence, all the other assignments would fail.
Oops. In short, I needed to assign it as an empty array and not
assume it would always receive a multi-valued assignment on the first
iteration of the loop.

Thanks again!

--Jonathan "smthng" Kalmes
http://smthng.info
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method invocation failed because [System.String] doesn't contain a method B Williams PowerShell 0 03-31-2008 06:00 PM
Method invocation failed B Williams PowerShell 0 03-31-2008 05:46 PM
psjob - Connection attempt failed. / Server execution failed Robin Moffatt PowerShell 10 02-06-2008 06:38 AM
RC1 upgrade failed... roll back failed... help? =?Utf-8?B?dGhlRG9u?= Vista General 1 09-26-2006 10:09 AM
Installation Failed at Extracting Files - rollback failed dismally CrAy-Z Vista installation & setup 0 06-24-2006 10:14 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50