how to fix DownloadFile error in powershell in windows10 [closed]

My guess would be that since you're connecting through https you may need to set a more secure schannel protocol to communicate with the site you're trying to download from.

add this line indicating security protocol before your webclient request

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$client = new-object System.Net.WebClient
$client.DownloadFile("https://www.cse.ust.hk/msbd5003/data/fruits.txt","D:\IT\fruits.txt")

Alternately, if you are only running this script from one machine, you can set .NET to use secure protocols by default.

You can read more about it at https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls

Key - HKEY_LOCAL_MACHINE\SOFTWARE\[Wow6432Node\]Microsoft\.NETFramework\<VERSION>
Name - SchUseStrongCrypto
Value - 1

Also, the native PowerShell cmdlet invoke-webrequest may simplify your request.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri "https://www.cse.ust.hk/msbd5003/data/fruits.txt" -OutFile "D:\IT\fruits.txt"