Welcome Forums General PowerShell Q&A Get-Credential not working

Viewing 5 reply threads
  • Author
    Posts
    • #174043
      Participant
      Topics: 8
      Replies: 13
      Points: 31
      Rank: Member

      $Username = ‘domain\username’
      $Password = ‘password’
      $pass = ConvertTo-SecureString -AsPlainText $Password -Force

      $SecureString = $pass
      # Users you password securly
      $MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList Username,$SecureString

      gwmi win32_service –credential $MySecureCreds

      I get : This command cannot be run due to the error : the user name or password is incorrect

      If I use an admin username and password it work!

      Can someone help?

       

    • #174058
      Participant
      Topics: 7
      Replies: 5
      Points: 64
      Rank: Member

      In your ArgumentList you are missing a $ in front of Username.

    • #174115
      Participant
      Topics: 8
      Replies: 13
      Points: 31
      Rank: Member

      The script I had was written with the $ before the Username

      Sorry, I mistake the transcript.

      Same issue, not woriking, always get This command cannot be run du to the error : the user name or password is incorrect.

      Work with administrator!

    • #174292
      Participant
      Topics: 8
      Replies: 13
      Points: 31
      Rank: Member

      Just to help somebodey taht ever come here for the same probleme!

      my internal domain name was : myinternalverylongdomainname.local

      So my username are  normally  : myinternalverylongdomainname\username

      In this case, the pre-windows 2000 name domain was “myinternal”

      So for the powershell get-credential to work I had to use myinternal\username

      Maybe it by design, but on the 350 domains that I manage it the only one with a such long internal domain name.

    • #174319
      Participant
      Topics: 0
      Replies: 115
      Points: 433
      Helping Hand
      Rank: Contributor

      David,

      How long is the domain name and user name each? Based on my testing Get-Credential is supporting up to 83 characters for the user and domain name. This was validated using UserPrincipalName and NT Login (Domain\UserName).

    • #174375
      Participant
      Topics: 8
      Replies: 13
      Points: 31
      Rank: Member

      20 for domain name and 10 for username

      I dont have any such long name like that on any of my other setup

      I spent a lot of time before I figure it out.

      I will try to reproduce this on a temp setup this week to see.

Viewing 5 reply threads
  • The topic ‘Get-Credential not working’ is closed to new replies.