Authenticating to a remote server using "UseDefaultCredentials"

This topic contains 3 replies, has 2 voices, and was last updated by  Dave Wyatt 2 years, 2 months ago.

  • Author
  • #38884

    Matt Penny

    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?


  • #38887

    Dave Wyatt

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

  • #38892

    Matt Penny

    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.

  • #38896

    Dave Wyatt

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

You must be logged in to reply to this topic.