document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. # Code Snippet from aperturescience.su
  2. Function Get-WebPage
  3. {
  4. <#
  5. .SYNOPSIS
  6. Get a webpage
  7.  
  8. .DESCRIPTION
  9. Gets the webpage at the specified URL and returns the string representation of that page. Webpages can be accessed over an URI including http://, Https://, file://, \\\\server\\folder\\file.txt etc.
  10.  
  11. .PARAMETER URL
  12. The url of the page we want to download and save as a string. URL must have format like: http://google.com, https://microsoft.com, file://c:\\test.txt
  13.  
  14. .PARAMETER Credentials
  15. [Optional] Credentials for remote server
  16.  
  17. .PARAMETER WebProxy
  18. [Optional] Web Proxy to be used, if none supplied, System Proxy settings will be honored
  19.  
  20. .PARAMETER Headers
  21. [Optional] Used to specify additional headers in HTTP request
  22.  
  23. .PARAMETER UserAgent
  24. [Optional] Simpler method of specifying useragent header
  25.  
  26. .INPUTS
  27. Nothing can be piped directly into this function
  28.  
  29. .OUTPUTS
  30. String representing the page at the specified URL
  31.  
  32. .EXAMPLE
  33. Get-Webpage "http://google.com"
  34. Gets the google page and returns it
  35.  
  36. .NOTES
  37. NAME: Get-WebPage
  38. AUTHOR: kieran@thekgb.su
  39. LASTEDIT: 2012-10-14 9:15:00
  40. KEYWORDS:
  41.  
  42. .LINK
  43. http://aperturescience.su/
  44. #>
  45. [CMDLetBinding()]
  46. Param
  47. (
  48.   [Parameter(mandatory=$true)] [String] $URL,
  49.   [System.Net.ICredentials] $Credentials,
  50.   [System.Net.IWebProxy] $WebProxy,
  51.   [System.Net.WebHeaderCollection] $Headers,
  52.   [String] $UserAgent
  53. )
  54.  
  55. #make a webclient object
  56. $webclient = New-Object Net.WebClient
  57. #set the pass through variables if they are not null
  58. if ($Credentials)
  59. {
  60.     $webclient.credentials = $Credentials
  61. }
  62. if ($WebProxy)
  63. {
  64.     $webclient.proxy = $WebProxy
  65. }
  66. if ($Headers)
  67. {
  68.     $webclient.headers.add($Headers)
  69. }
  70. if ($UserAgent)
  71. {
  72.     $webclient.headers["User-Agent"] = $UserAgent
  73. }
  74.  
  75. #Set the encoding type, we will use UTF8
  76. $webclient.Encoding = [System.Text.Encoding]::UTF8
  77.  
  78. #contains resultant page
  79. $result = $null
  80.  
  81. #call download string and return the string returned (or any errors generated)
  82. try
  83. {
  84.     $result = $webclient.downloadstring($URL)
  85. }
  86. catch
  87. {
  88.     throw $_
  89. }
  90.  
  91. return $result
  92.  
  93. }
  94. # Code Snippet from aperturescience.su
');