Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. ######################################################################################
  2. #To use this script, the properties of each active directory user must be populated with their mobile number.
  3. #Under the properties of an a/d user there is the Telephones tab. The mobile field must contain the mobile number and in the correct format.
  4. #For example if my carrier is verizon, I would use 1234567899@vtext.com.
  5. #The first section defines authentication to the email server. The email field needs to be updated to reflect your environment.
  6. #Don't declare a ‘to’ field, as it's used at the #end. Modify the from,body,sub,creduser,credpass,smtpserver,and port fields.
  7. ##
  8. $From = "emergencytest@yourdomain.com
  9. $Body = "This is a test of the WatchPoint emergency broadcast system. This is only a test."
  10. $Sub = "Test of the WatchPoint emergency broadcast system"
  11. $CredUser = "myuser@mydomain.com"
  12. $CredPass = "password" | ConvertTo-SecureString -AsPlainText -Force
  13. $Credentials = New-Object System.Management.Automation.Pscredential -Argumentlist $CredUser,$CredPass
  14. $SmtpServer = "mail.mydomain.com"
  15. $Port = "587"
  16.  
  17. #Declare the csv paths. The paths will need to be updated to reflect your environment.
  18. ##
  19. $exportmembers = "C:\test\watchpointdata.csv"
  20. $exportresults = "C:\test\results.csv"
  21.  
  22. #Replace “WatchPointData” with your distribution groups actual name. Keep the “”.
  23. #This section collects all of the members that belong to our hidden distribution group and exports to a csv.
  24. ##
  25. $members = get-adgroupmember "WatchPointData" | select-object -property "SamAccountName" | export-csv $exportmembers
  26.  
  27. #Nothing needs changed here. This section collects the name,login, and mobile phone number for each member of the group and is used in the next section.
  28. ##
  29. Import-CSV -Path $exportmembers | ForEach-Object {
  30. Get-ADUser -Filter "SamAccountName -like '*$($_.SamAccountName)*'" -Properties MobilePhone,UserPrincipalName,Name | select Name,UserPrincipalName,MobilePhone
  31. } | Export-CSV $exportresults -NoTypeInformation
  32.  
  33. #Nothing needs changed here. This section gathers just the "MobilePhone" number that we exported from the above section.
  34. ##
  35. $textnumbers = import-csv $exportresults | % {$_.MobilePhone}
  36.  
  37. #Nothing needs to be changed here. This section sends an email as text to each user.
  38. ##
  39. ForEach($cellnumber in $textnumbers)
  40. {
  41. Send-MailMessage -To $cellnumber -From $From -Body $Body -Subject $Sub -Credential $Credentials -SmtpServer $smtpServer -Port $Port
  42. }
  43. #End of Script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement