Advertisement
Guest User

Untitled

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