Author Posts

January 1, 2012 at 12:00 am

by j-me at 2013-04-04 06:11:14

what does this mean and how to handle/code for this exception:

error msg in ps window:

Exception calling "InvokeMethod" with "2" argument(s): "The parameter is incorr
ect."
At C:\suspend\Save_Suspended_msgs.ps1:62 char:31
+ $msg.psbase.invokemethod < <<< ('SaveToFile', ($newpath))
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

script:

if (!$msg.psbase.length)
{
"Length is NULL"
$msg.psbase.invokemethod('SaveToFile', ($newpath))
"Message from ServiceInstanceID=$msgid saved to $newpath."
$error[0]|format-list -force > susp_err-$msgid-$sname.txt
}
else
{
if ($msg.psbase.length -gt 0)
{

foreach($m in $msg)
{

$m.psbase.invokemethod('SaveToFile', ($newpath))
"Message from ServiceInstanceID=$msgid saved to $newpath."

$error[0]|format-list -force > susp_err-$msgid-$sname.txt
}
}
}
}

long listing of message from $error[0]|format-list -force

Exception : System.Management.Automation.MethodInvocationException:
Exception calling "InvokeMethod" with "2" argument(s):
"The parameter is incorrect." ---> System.ArgumentExce
ption: The parameter is incorrect.
at System.Runtime.InteropServices.Marshal.ThrowExcep
tionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Management.ManagementObject.InvokeMethod(S
tring methodName, ManagementBaseObject inParameters, In
vokeMethodOptions options)
at System.Management.ManagementObject.InvokeMethod(S
tring methodName, Object[] args)
at InvokeMethod(Object , Object[] )
at System.Management.Automation.DotNetAdapter.Auxili
aryMethodInvoke(Object target, Object[] arguments, Meth
odInformation methodInformation, Object[] originalArgum
ents)
--- End of inner exception stack trace ---
at System.Management.Automation.DotNetAdapter.Auxili
aryMethodInvoke(Object target, Object[] arguments, Meth
odInformation methodInformation, Object[] originalArgum
ents)
at System.Management.Automation.DotNetAdapter.Method
InvokeDotNet(String methodName, Object target, MethodIn
formation[] methodInformation, Object[] arguments)
at System.Management.Automation.Adapter.BaseMethodIn
voke(PSMethod method, Object[] arguments)
at System.Management.Automation.ParserOps.CallMethod
(Token token, Object target, String methodName, Object[
] paramArray, Boolean callStatic, Object valueToSet)
at System.Management.Automation.MethodCallNode.Invok
eMethod(Object target, Object[] arguments, Object value
)
at System.Management.Automation.MethodCallNode.Execu
te(Array input, Pipe outputPipe, ExecutionContext conte
xt)
at System.Management.Automation.ParseTreeNode.Execut
e(Array input, Pipe outputPipe, ArrayList& resultList,
ExecutionContext context)
at System.Management.Automation.StatementListNode.Ex
ecuteStatement(ParseTreeNode statement, Array input, Pi
pe outputPipe, ArrayList& resultList, ExecutionContext
context)
TargetObject :
CategoryInfo : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : DotNetMethodException
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
PipelineIterationInfo : {}
PSMessageDetails :

thank you!

by DonJ at 2013-04-04 08:09:14

The error means one of your parameters isn't accepted by the method InvokeMethod(). Which is a bit of an odd way to call a method, but without knowing what's in $m, I'm not sure what additional advice to offer. I'm also not sure which InvokeMethod() it's upset about because you've only included a portion of your script. It's the one on line 62 of your script.

If it's the line where you use $msg.psbase.InvokeMethod(), it's because $msg is a collection (I'm assuming, since you ForEach it later in the code), and you can't invoke a method on a collection. Well, you can in v3, but not how you're doing it.

Anyway, it's kinda odd-looking code.

by nohandle at 2013-04-04 08:43:58

[quote="j-me"]$error[0]|format-list -force[/quote]
This may also give you better insight on what exactly failed and why:
$error[0].exception | format-list * -force
$error[0].exception.innerexception | format-list -force