Download File using WebClient

PS C:\Windows\System32> $url = "http://127.0.0.1/download.php"
PS C:\Windows\System32> $wc = New-Object System.Net.WebClient
PS C:\Windows\System32> $wc.OpenRead($url)
CanTimeout    : True
ReadTimeout   : 300000
WriteTimeout  : 300000
CanRead       : True
CanSeek       : False
CanWrite      : False
Length        :
Position      :
PS C:\Windows\System32> $filesize = $wc.ResponseHeaders["Content-Length"]
PS C:\Windows\System32> $filesize
102400
PS C:\Windows\System32> $output = [System.Environment]::GetFolderPath("desktop") + "\output.exe"
PS C:\Windows\System32> $wc.DownloadFile($url, $output)
PS C:\Windows\System32> Start-Process $output
PS C:\Windows\System32> 


Download File using Invoke-WebRequest

PS C:\Windows\System32> $url = "http://127.0.0.1/download.php"
PS C:\Windows\System32> $response = Invoke-WebRequest -Uri $url -ErrorAction Ignore
PS C:\Windows\System32> $filesize = $response.Headers["Content-Length"]
PS C:\Windows\System32> $filesize
102400
PS C:\Windows\System32> $output = [System.Environment]::GetFolderPath("desktop") + "\output.exe"
PS C:\Windows\System32> Invoke-WebRequest -Uri $url -OutFile $output
PS C:\Windows\System32> Start-Process $output
PS C:\Windows\System32> 


신고

티스토리 툴바