I'm relatively new to Powershell so really not sure where to go with this issue now. I am trying to download a file from a subversion repository and am getting the (401) Unauthorized" error. I am able to log into the site and download the file using IE using the exact Same credentials on the same machine.
$source = "http://repository/folder/File.exe"
$destination = "E:\Temp\File.exe"
$wc = New-Object System.Net.WebClient
$pwd=convertto-securestring -string "password" -AsPlainText -force
$creds=New-Object System.Management.Automation.PSCredential -ArgumentList $user, $pwd
$wc.Credentials = New-Object System.Net.NetworkCredential ($user, $Creds.GetNetworkCredential().Password,"DOMAIN")
Are you using basic auth on your iis/apache? If so try this:
$source = "http://repository/folder/File.exe" $destination = "E:\Temp\File.exe" $wc = new-object System.Net.WebClient $credCache = new-object System.Net.CredentialCache $creds = new-object System.Net.NetworkCredential($user,$pwd) $credCache.Add($source, "Basic", $creds) $wc.Credentials = $credCache $wc.DownloadFile($source, $destination)