Get-Credential not working

$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?

 

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

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!

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.

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).

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.