Advertisement
smartguy5000

Get-TornVitals.ps1

Jun 18th, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Param(
  2.     $selector = 'bars,notifications',
  3.     $apikey = '{apikeyhere}'
  4. )
  5. $uri = "https://api.torn.com/user/?selections=$($selector)&key=$($apikey)"
  6. $username = 'email@domain.com'
  7. $password = Get-Content 'c:\fakepath\mysecurestring.txt' | ConvertTo-SecureString
  8. $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$password
  9. $to = 'you@you.com'
  10. $from = $username
  11. $smtpserver = 'smtp.example.com'
  12. $port = '465 OR 587'
  13. $subject = 'desired subject line of notification email'
  14.  
  15. $request = Invoke-WebRequest -Uri $uri
  16.  
  17. $content = $request.Content
  18.  
  19. $contentObj = ConvertFrom-Json -InputObject $content
  20.  
  21. $properties = Get-Member -InputObject $contentObj -MemberType NoteProperty
  22.  
  23. $checkArray = New-Object -TypeName System.Collections.ArrayList
  24.  
  25. ForEach ($property in $properties)
  26. {
  27.     If ($property.MemberType -eq 'NoteProperty')
  28.     {
  29.        
  30.             If ($Property.Name -ne 'chain' -AND $Property.Name -ne 'notifications' -AND $Property.Name -ne 'server_time')
  31.             {
  32.                 $checkArray.Add($Property.Name)
  33.             }
  34.        
  35.     }
  36. }
  37.  
  38. ForEach ($item in $checkArray)
  39. {
  40.     If ($contentObj.$item.fulltime -ne 0)
  41.     {
  42.         If ($contentObj.$item.fulltime -le 900)
  43.         {
  44.             $mins = $contentObj.$item.Fulltime/60
  45.             $mins = [math]::Round($mins)
  46.            $msg = "$item has $mins minutes remaining til full"
  47.            Send-MailMessage -To $to -From $from -Body $msg -Subject $subject -smtpserver $smtpserver  -UseSsl -Credential $cred -port $port
  48.         }
  49.        
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement