Advertisement
Guest User

Untitled

a guest
Aug 6th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. Function MassIM
  2. {
  3. Try
  4. {
  5. $Excel = New-Object -ComObject Excel.Application
  6. $Excel.Visible = $False
  7. }
  8. Catch [System.Exception]
  9. {
  10. $TS = TimeStamp
  11. "${TS}:Could not load Excel." | OutputToError
  12. Throw FatalError
  13. }
  14.  
  15. Try
  16. {
  17. $IMBook = $Excel.Workbooks.Open("C:\IMList.xls")
  18. }
  19. Catch [System.Exception]
  20. {
  21. $TS = TimeStamp
  22. "${TS}:Could not open required workbook." | OutputToError
  23. Throw FatalError
  24. }
  25.  
  26. Try
  27. {
  28. $IMSheet = $IMBook.Worksheets.Item(1)
  29. }
  30. Catch [System.Exception]
  31. {
  32. $TS = TimeStamp
  33. "${TS}:Could not open required worksheet." | OutputToError
  34. Throw FatalError
  35. }
  36.  
  37. Try
  38. {
  39. $AssemblyPath = “C:\Program Files (x86)\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.Lync.Model.DLL”
  40. Import-Module $AssemblyPath
  41. }
  42. Catch [System.Exception]
  43. {
  44. $TS = TimeStamp
  45. "${TS}:Could not load required DLL files" | OutputToError
  46. Throw FatalError
  47. }
  48.  
  49. Try
  50. {
  51. $LyncClient = [Microsoft.Lync.Model.LyncClient]::GetClient()
  52. }
  53. Catch [System.Exception]
  54. {
  55. $TS = TimeStamp
  56. "${TS}:Could not connect to Lync client." | OutputToError
  57. Throw FatalError
  58. }
  59.  
  60. $FoundEmptyCell = $False
  61. $Row = 1
  62.  
  63. While (!$FoundEmptyCell)
  64. {
  65. If ($IMSheet.Cells.Item($Row, 1).Value() -EQ $null)
  66. {
  67. $FoundEmptyCell = $True
  68. }
  69. Else
  70. {
  71. Try
  72. {
  73. $User = $IMSheet.Cells.Item($Row, 1).Value()
  74. $UserDesk = $IMSheet.Cells.Item($Row, 2).Value()
  75. $UserExt = $IMSheet.Cells.Item($Row, 3).Value()
  76. }
  77. Catch [System.Exception]
  78. {
  79. $TS = TimeStamp
  80. "${TS}:Could not load data from worksheet." | OutputToError
  81. Throw FatalError
  82. }
  83. $User = $User -split ','
  84. $UserName = $User[1] + "." + $User[0] + "@user.com"
  85. $UserName.Trim()
  86.  
  87. Try
  88. {
  89. $Convo = $LyncClient.ConversationManager.AddConversation()
  90. $MSG = New-Object "System.Collections.Generic.Dictionary[Microsoft.Lync.Model.Conversation.InstantMessageContentType,String]"
  91. $MSG.Add(0, "Hello ${UserName}. Is your desk still ${UserDesk}? Is your extension still ${UserExt}?")
  92. $null = $Convo.AddParticipant($UserName)
  93. }
  94. Catch [System.Exception]
  95. {
  96. $TS = TimeStamp
  97. "${TS}:Could not initiate conversation." | OutputToError
  98. Throw FatalError
  99. }
  100.  
  101. Try
  102. {
  103. $Mod = $Convo.Modalities[1]
  104. $null = $Mod.BeginSendMessage($MSG, $null, $MSG)
  105. }
  106. Catch [System.Exception]
  107. {
  108. $TS = TimeStamp
  109. "${TS}:Could not instant message${UserName}." | OutputToError
  110. $Error | OutputToError
  111. }
  112. $Row++
  113. }
  114. }
  115.  
  116. $Excel.Quit()
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement