# Authenticating to a remote server using "UseDefaultCredentials"

**URL:** <https://forums.powershell.org/t/authenticating-to-a-remote-server-using-usedefaultcredentials/6420>\
**Category:** PowerShell Help\
**Created:** [May 10, 2016, 3:35am UTC](https://forums.powershell.org/t/authenticating-to-a-remote-server-using-usedefaultcredentials/6420 "2016-05-10T03:35:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt-penny](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@matt-penny](https://forums.powershell.org/u/matt-penny)\
**Post date:** [May 10, 2016, 3:35am UTC](https://forums.powershell.org/t/authenticating-to-a-remote-server-using-usedefaultcredentials/6420/1 "2016-05-10T03:35:25Z")

</div>

Hey everyone,

I’m currently working on a script that uploads a file to a remote sharepoint server - the script below is what is currently being used:

```
$UploadFile = Get-ChildItem $CSV_File

# put the file up on SharePoint
$webclient = New-Object System.Net.WebClient

# set credentials to use
$securePassword = ConvertTo-SecureString '' -AsPlainText -force

$credentials = new-object System.Management.Automation.PSCredential ("Domain\Account", $securePassword)

# upload file
$webclient.UploadFile($destination + "/data.csv", "PUT", $Data.csv.FullName)
```

This method works just fine and uploads the resource to the server. However, I need to authenticate/upload to the remote server _without_ storing the account credentials anywhere on the box. I’ve done this in the past by utilizing the “UseDefaultCredentials” property:

```
$webclient.UseDefaultCredentials = $true
```

However, even when switched to True, the credentials aren’t stored and authentication fails. Is there any reason in particular it wouldn’t be storing the credentials properly, and can another method be implemented to avoid storing credentials on the server?

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [May 10, 2016, 3:55am UTC](https://forums.powershell.org/t/authenticating-to-a-remote-server-using-usedefaultcredentials/6420/2 "2016-05-10T03:55:56Z")

</div>

How are you executing the script? Interactively, from a scheduled task, through PSRemoting, etc?

---

<div class="post-metadata">

**Author:** ![matt-penny](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@matt-penny](https://forums.powershell.org/u/matt-penny)\
**Post date:** [May 10, 2016, 4:06am UTC](https://forums.powershell.org/t/authenticating-to-a-remote-server-using-usedefaultcredentials/6420/3 "2016-05-10T04:06:23Z")

</div>

Hey Dave,

Presently, I’m testing it interactively (Running directly on the box) - however, this script is going to be moved over/rolled into to scheduled tasks on the server once it’s fixed.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [May 10, 2016, 4:58am UTC](https://forums.powershell.org/t/authenticating-to-a-remote-server-using-usedefaultcredentials/6420/4 "2016-05-10T04:58:56Z")

</div>

Does the website you’re uploading to have Windows Authentication enabled? That’s required for UseDefaultCredentials to work.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:42pm UTC](https://forums.powershell.org/t/authenticating-to-a-remote-server-using-usedefaultcredentials/6420/5 "2024-05-16T20:42:33Z")

</div>


