Author Posts

May 10, 2016 at 9:05 am

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!

May 10, 2016 at 9:25 am

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

May 10, 2016 at 9:36 am

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.

May 10, 2016 at 10:28 am

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