Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######################################################################################
- #To use this script, the properties of each active directory user must be populated with their mobile number.
- #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.
- #For example if my carrier is verizon, I would use 1234567899@vtext.com.
- #The first section defines authentication to the email server. The email field needs to be updated to reflect your environment.
- #Don't declare a ‘to’ field, as it's used at the #end. Modify the from,body,sub,creduser,credpass,smtpserver,and port fields.
- ##
- $From = "emergencytest@yourdomain.com
- $Body = "This is a test of the WatchPoint emergency broadcast system. This is only a test."
- $Sub = "Test of the WatchPoint emergency broadcast system"
- $CredUser = "myuser@mydomain.com"
- $CredPass = "password" | ConvertTo-SecureString -AsPlainText -Force
- $Credentials = New-Object System.Management.Automation.Pscredential -Argumentlist $CredUser,$CredPass
- $SmtpServer = "mail.mydomain.com"
- $Port = "587"
- #Declare the csv paths. The paths will need to be updated to reflect your environment.
- ##
- $exportmembers = "C:\test\watchpointdata.csv"
- $exportresults = "C:\test\results.csv"
- #Replace “WatchPointData” with your distribution groups actual name. Keep the “”.
- #This section collects all of the members that belong to our hidden distribution group and exports to a csv.
- ##
- $members = get-adgroupmember "WatchPointData" | select-object -property "SamAccountName" | export-csv $exportmembers
- #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.
- ##
- Import-CSV -Path $exportmembers | ForEach-Object {
- Get-ADUser -Filter "SamAccountName -like '*$($_.SamAccountName)*'" -Properties MobilePhone,UserPrincipalName,Name | select Name,UserPrincipalName,MobilePhone
- } | Export-CSV $exportresults -NoTypeInformation
- #Nothing needs changed here. This section gathers just the "MobilePhone" number that we exported from the above section.
- ##
- $textnumbers = import-csv $exportresults | % {$_.MobilePhone}
- #Nothing needs to be changed here. This section sends an email as text to each user.
- ##
- ForEach($cellnumber in $textnumbers)
- {
- Send-MailMessage -To $cellnumber -From $From -Body $Body -Subject $Sub -Credential $Credentials -SmtpServer $smtpServer -Port $Port
- }
- #End of Script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement