-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPowerShell-Get-WebPage
More file actions
47 lines (40 loc) · 826 Bytes
/
Copy pathPowerShell-Get-WebPage
File metadata and controls
47 lines (40 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Function Get-WebPage
{
[CMDLetBinding()]
Param
(
[Parameter(mandatory=$true)] [String] $URL,
[System.Net.ICredentials] $Credentials,
[System.Net.IWebProxy] $WebProxy,
[System.Net.WebHeaderCollection] $Headers,
[String] $UserAgent
)
$webclient = New-Object Net.WebClient
if ($Credentials)
{
$webclient.credentials = $Credentials
}
if ($WebProxy)
{
$webclient.proxy = $WebProxy
}
if ($Headers)
{
$webclient.headers.add($Headers)
}
if ($UserAgent)
{
$webclient.headers["User-Agent"] = $UserAgent
}
$webclient.Encoding = [System.Text.Encoding]::UTF8
$result = $null
try
{
$result = $webclient.downloadstring($URL)
}
catch
{
throw $_
}
return $result
}