Authenticating to a remote server using "UseDefaultCredentials"

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 4 months, 2 weeks ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #38884
    Profile photo of Matt Penny
    Matt Penny
    Participant

    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!

    #38887
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

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

    #38892
    Profile photo of Matt Penny
    Matt Penny
    Participant

    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
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

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

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.