【问题标题】:How to fetch messages from a lync conversation using powershell?如何使用 powershell 从 lync 对话中获取消息?
【发布时间】:2018-05-28 10:41:06
【问题描述】:

我进行了一些研究,并找到了一种利用 Lync 2013 SDK 向我的联系人列表中的联系人发送 IM 的方法。但是,如果有一种方法可以从对话窗口中获取消息,那将会更加有用。

【问题讨论】:

  • 您可以添加您研究的内容、问题所在以及所需的输出吗?看看how to ask
  • link 我以此为指导,编写了一个通过 lync 发送消息的小脚本。

标签: powershell automation lync


【解决方案1】:

Sample send receive Lync / Skype for business messages using powershell(作者:Grzegorz Kulikowski)

与其他用户一起测试

cd "C:\Program Files (x86)\Microsoft Office\Office15\lyncsdk\Assemblies\Desktop"
Import-Module .\Microsoft.Lync.Model.dll
$Client = [Microsoft.Lync.Model.LyncClient]::GetClient()
$Conversation = $client.ConversationManager.AddConversation()
$person=$client.ContactManager.GetContactByUri('person@domain.com')
$conversation.AddParticipant($person)


Get-EventSubscriber|Unregister-Event
# For each participant in the conversation

$conversation.Participants | Where { !$_.IsSelf } | foreach {
    Register-ObjectEvent -InputObject $_.Modalities[1] -EventName "InstantMessageReceived" -SourceIdentifier "person $i" -action { 
    $global:conv = $event
    $msg = $conv.SourceEventArgs.Text.trim()
    write-host $msg
    switch -Wildcard ($msg) {
     "What*" {$Conversation.Modalities['InstantMessage'].BeginSendMessage((Invoke-Expression $msg.split()[-1]), {}, 0)}
     "Hello" {$Conversation.Modalities['InstantMessage'].BeginSendMessage("Hello human", {}, 0)}
     "stupid robot" {$Conversation.Modalities['InstantMessage'].BeginSendMessage("Humanity is overrated", {}, 0)}
    }
    }
    $i++
   }

自己测试

cd "C:\Program Files (x86)\Microsoft Office\Office15\lyncsdk\Assemblies\Desktop"
Import-Module .\Microsoft.Lync.Model.dll
$Client = [Microsoft.Lync.Model.LyncClient]::GetClient()
$Conversation = $client.ConversationManager.AddConversation()
$conversation.AddParticipant($client.Self.Contact)

Get-EventSubscriber|Unregister-Event
  $conversation.Participants[0]| foreach {
    Register-ObjectEvent -InputObject $_.Modalities[1] -EventName "InstantMessageReceived" -SourceIdentifier "person $i" -action { 
    $global:conv = $event
    $msg = $conv.SourceEventArgs.Text.trim()
    write-host $msg
    #if ($msg -like 'What*') {$Conversation.Modalities['InstantMessage'].BeginSendMessage((Invoke-Expression $msg.split()[-1]), {}, 0)}
    switch -Wildcard ($msg) {
     "What*" {$Conversation.Modalities['InstantMessage'].BeginSendMessage((Invoke-Expression $msg.split()[-1]), {}, 0)}
     "Hello" {$Conversation.Modalities['InstantMessage'].BeginSendMessage("Hello human", {}, 0)}
     "stupid robot" {$Conversation.Modalities['InstantMessage'].BeginSendMessage("Humanity is overrated", {}, 0)}
    }
    }
    $i++
   }

此外,这些可能会有所帮助:

Send and receive text in a conversation

Learn Skype Web SDK Day 15 : Receiving Instant Messages

【讨论】:

  • 尝试此脚本时出现此错误:format-default : Exception has been thrown by the target of an invocation. + CategoryInfo : NotSpecified: (:) [format-default], TargetInvocationException + FullyQualifiedErrorId : System.Reflection.TargetInvocationException,Microsoft.PowerShell.Co mmands.FormatDefaultCommand
  • @KarthicSrinivasan 您是否按照我的答案顶部的链接中的说明安装了 Lync SDK 包? Sample send receive Lync / Skype for business messages using powershell?它说:“在开始之前,您需要获取 Lync SDK 包:lyncsdk.exe
  • 是的,我已经安装了 lynk sdk。仍然收到错误。这行$conversation.AddParticipant($person) 正在抛出这个异常
  • 很难说不知道您的设置细节,即操作系统、PowerShell 版本、您使用的帐户等等。对异常文本的搜索显示:Exception has been thrown while reading SSA via PowerShell .祝你好运!
猜你喜欢
  • 1970-01-01
  • 2021-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-29
  • 1970-01-01
  • 2018-07-06
  • 1970-01-01
相关资源
最近更新 更多