PScredential class is not storing the credentials provided in script

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 9 months, 1 week ago.

  • Author
    Posts
  • #61866

    Ankur
    Participant

    Dear All,

    I am trying to copy the text file “1.txt” to remote share location using start-bitstransfer. I want to copy using a service account that has modify permission on remote share. Below is the code I am working with. However when I run it in Powershell ISE (admin context) I get error -> Start-BitsTransfer : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))access denied. It seems that PScredential class is not storing the credentials provided in script. I say this because when I run the same script to copy “1.txt” to different remote location in Powershell ISE (admin context) it gets copied irrespective of random values I supply in $username & $password variable. Would like to know your thoughts on this. Thanks.

    $share = "\\remote\share\"
    $username = "domain\username"
    $password = “Maz@0*S[f5” | convertto-securestring -AsPlainText -Force
    $Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
    Start-BitsTransfer -Priority High -Credential $Credential -RetryTimeout 120 -RetryInterval 60 -Source “C:\Programdata\1.txt” -Destination $share

  • #61935

    Don Jones
    Keymaster

    As a test, try creating $Credential using New-PSCredential.

You must be logged in to reply to this topic.