Guest User

Untitled

a guest
Nov 11th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. function Send-Notification () {
  2. param (
  3. [parameter(Mandatory = $true)]$body
  4. )
  5.  
  6. [Byte[]] $key = (1..16)
  7. $params = Import-PowerShellDataFile "$PSScriptRoot\GMailConfiguration.psd1"
  8. $Today = Get-Date -Format "yyyy-MM-dd hh:mm"
  9.  
  10. $params.add('body', $body)
  11. $subject = $params.Get_Item('subject') + ': ' + $Today
  12. $params.Set_Item('subject', $subject)
  13.  
  14.  
  15. #create an email
  16. $emailusername = $params.Get_Item('from')
  17. $recipientname = $params.Get_Item('to')
  18. $password = $params.Get_Item('securestring') | Out-String | ConvertTo-SecureString -Key $key
  19. $credential = New-Object System.Management.Automation.PsCredential($emailusername, $password)
  20.  
  21. $params.Remove('securestring')
  22.  
  23.  
  24. try {
  25. Send-MailMessage @params -Credential $credential -UseSsl -ErrorAction Stop
  26. Write-Log "SOLR notification was sent to $recipientname"
  27. }
  28. Catch {
  29. Write-Log "Check email settings"
  30. throw "An error occured."
  31. }
  32. }
Add Comment
Please, Sign In to add comment