![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 |
| | #2 (permalink) |
| 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 |
| | #3 (permalink) |
| 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 notassume it would always receive a multi-valued assignment on the first iteration of the loop. Thanks again! --Jonathan "smthng" Kalmes http://smthng.info |
| |
| |
![]() |
| 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 |