Hi all - I am running a simple powershell command in a ps script to return a value, to be used later for reporting in scom. However I am getting an error when running it - script is below:
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
$Mailflow = Test-Mailflow | select @{n='MailFlowLatency-(Seconds)';e={$_.messagelatencytime.totalseconds}}
$Mailflow.'MailFlowLatency-(Seconds)'.ToString()
$api = new-object -comObject 'MOM.ScriptAPI'
$bag = $api.CreatePropertyBag()
$bag.AddValue('Mailflow', $Mailflow)
$api.Return($Bag)
$bag
Every time i run this - or even other scripts returning values, i get the same error:
Exception calling "Return" with "1" argument(s): "Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"
At C:\temp\test.ps1:11 char:1
+ $api.Return($Bag)
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation
I've noticed that this error appears with other users too when doing a google search, but nothing concrete as to what the problem may be. The command itself works fine, and removing the return line removes the error, so i can only assume it is that line that is causing the problem, as i cant see an issue with the powershell itself given that it works.
Any help would be much appreciated!! Thx in advance..