Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. function InvokeWebRequest ([string]$url)
  2. {
  3. try
  4. {
  5. $webrequest = [System.Net.WebRequest]::Create($url)
  6. $response = $webrequest.GetResponse()
  7. $stream = $response.GetResponseStream()
  8. $sr = new-object System.IO.StreamReader($stream)
  9. $content = $sr.ReadToEnd();
  10. return $content
  11. }
  12. catch { Write-Error $_.Exception.Message }
  13. finally
  14. {
  15. if($sr -ne $null) { $sr.Close(); }
  16. if($response -ne $null) { $response.Close(); }
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement