Download File using WebClient
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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
1 2 3 4 5 6 7 8 9 | 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> |