1

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
$user="user"
$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")

$download=$wc.DownloadFile($source, "$destination")

Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (401) Unauthorized."

Any ideas if this is cross platform issue? And how to get around this?

Thanks

1 Answer 1

6

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)
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the quick response. We are indeed using basic auth on the Apache and the above works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.