0

我正在尝试执行单个联系人 IM 的脚本(通过 Microsoft Lync),并已成功运行脚本一直到最后一行:

$null = $m.BeginSendMessage($d, $null, $d)

笔记:

$d = New-Object "System.Collections.Generic.Dictionary [Microsoft.Lync.Model.Conversation.InstantMessageContentType, String]"

$d.Add($PlainText, "This is a test.")

以下是执行此语法时 Psh 引发的异常。它似乎在启动 $null 变量时失败。

Exception calling "BeginSendMessage" with "3" argument(s): "Value does not fall within the expected range."
At C:\ScriptsPS\IM_SingleContact.ps1:75 char:1
+ $null = $m.BeginSendMessage($d, $null, $d)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4

1 回答 1

0

第二个参数必须是回调方法。在 Powershell 中使用 AsyncCallback有一个简单的例子:

$myCallback = [AsyncCallback]{
  param( $asyncResult)
  # callback code
  if ($asyncResult.isCompleted) {
    Write-Host "Message Sent"
  }
}
[void]$m.BeginSendMessage($d, $myCallback, $d)
于 2013-10-08T19:03:05.913 回答