Welcome Forums General PowerShell Q&A PScredential class is not storing the credentials provided in script

Viewing 1 reply thread
  • Author
    Posts
    • #61866
      Participant
      Topics: 1
      Replies: 0
      Points: 0
      Rank: Member

      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
      Keymaster
      Topics: 18
      Replies: 4872
      Points: 1,902
      Helping HandTeam Member
      Rank: Community Hero

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

Viewing 1 reply thread
  • The topic ‘PScredential class is not storing the credentials provided in script’ is closed to new replies.