smartguy5000

Get-TornVitals.ps1

Jun 18th, 2018
246
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 protected]'
  7. $password = Get-Content 'c:\fakepath\mysecurestring.txt' | ConvertTo-SecureString
  8. $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$password
  9. $from = $username
  10. $smtpserver = 'smtp.example.com'
  11. $port = '465 OR 587'
  12. $subject = 'desired subject line of notification email'
  13.  
  14. $request = Invoke-WebRequest -Uri $uri
  15.  
  16. $content = $request.Content
  17.  
  18. $contentObj = ConvertFrom-Json -InputObject $content
  19.  
  20. $properties = Get-Member -InputObject $contentObj -MemberType NoteProperty
  21.  
  22. $checkArray = New-Object -TypeName System.Collections.ArrayList
  23.  
  24. ForEach ($property in $properties)
  25. {
  26.     If ($property.MemberType -eq 'NoteProperty')
  27.     {
  28.        
  29.             If ($Property.Name -ne 'chain' -AND $Property.Name -ne 'notifications' -AND $Property.Name -ne 'server_time')
  30.             {
  31.                 $checkArray.Add($Property.Name)
  32.             }
  33.        
  34.     }
  35. }
  36.  
  37. ForEach ($item in $checkArray)
  38. {
  39.     If ($contentObj.$item.fulltime -ne 0)
  40.     {
  41.         If ($contentObj.$item.fulltime -le 900)
  42.         {
  43.             $mins = $contentObj.$item.Fulltime/60
  44.             $mins = [math]::Round($mins)
  45.            $msg = "$item has $mins minutes remaining til full"
  46.            Send-MailMessage -To $to -From $from -Body $msg -Subject $subject -smtpserver $smtpserver  -UseSsl -Credential $cred -port $port
  47.         }
  48.        
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment