Guest User

Untitled

a guest
Apr 1st, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. .Synopsis
  3.    Short description
  4. .DESCRIPTION
  5.    Long description
  6. .EXAMPLE
  7.    Example of how to use this cmdlet
  8. .EXAMPLE
  9.    Another example of how to use this cmdlet
  10. #>
  11. function Get-RedditComments
  12. {
  13.     [CmdletBinding()]
  14.     [Alias()]
  15.     [OutputType([int])]
  16.     Param
  17.     (
  18.         # Param1 help description
  19.         [Parameter(Mandatory=$true,
  20.                    ValueFromPipelineByPropertyName=$true,
  21.                    Position=0)]
  22.         [string]
  23.         $Username
  24.     )
  25.  
  26.     Begin
  27.     {
  28.     }
  29.     Process
  30.     {
  31.         $CommentsHTML = Invoke-WebRequest -uri "https://www.reddit.com/user/$username"
  32.         $Comments = $commentshtml.ParsedHtml.getElementsByTagName("Div") | ?{$_.ClassName -like " Thing *"}
  33.         Foreach ($comment in $comments)
  34.         {
  35.             $commentarray = $comment.innertext.split("`n")
  36.             Try
  37.             {
  38.                 $title = $commentarray | select -first 1
  39.                 $body = $commentarray | select -last ($commentarray.count - 3) | select -first ($commentarray.count - 9)  
  40.                 $day = (($comment.outerhtml).split(' ') | ? {$_ -like "*datetime*"}).split("`"")[1].split("T+")[0]
  41.                 $time = (($comment.outerhtml).split(' ') | ? {$_ -like "*datetime*"}).split("`"")[1].split("T+")[1]
  42.                 $offset = (($comment.outerhtml).split(' ') | ? {$_ -like "*datetime*"}).split("`"")[1].split("T+")[2]
  43.                 $date = get-date -month $day.split("-")[1] -day $day.split("-")[2] -year $day.split("-")[0] -hour $time.split(":")[0] -minute $time.split(":")[1] -Second $time.split(":")[2]
  44.                 $props = @{ ‘Username’=$username
  45.                             ‘Title’=$title
  46.                             ‘Comment’=$body
  47.                             'Date'=$date
  48.                           }
  49.                 $obj = New-Object -TypeName PSObject -Property $props
  50.                 Write-Output $obj
  51.             }
  52.             Catch
  53.             {
  54.             }
  55.         }
  56.     }
  57.     End
  58.     {
  59.     }
  60. }
Add Comment
Please, Sign In to add comment