I run a powershell command to list all of the services on a remote matchine:
$b = 0;
get-wmiobject win32_service -computer $computerName -credential $cred | select-object Name, @{n='Counter';e={$script:b+=1;$b}} | % "{0}: {1}" -f $_.Counter, $_.Name }
This works the first time I run it. Sometimes it works the second time. Then it stops working part way through with an Access Denied error. I then discover that my account is locked on the remote machine. I get the account unlocked, run the script a few times, and I'm locked out again. WTF?
Why would accessing a remote machine using WMI lock my account on the machine?
How can I stop it happening?
Supporting Information
I'm quering the remote machine using a name and password of an account local to the machine. I'm not using a domain account.
The remote machine is running Windows Server 2008 R2.
By "stopping part way" I mean that it prints out around 20 of the services and then gets the error.
After More Investigation
This might be an anomaly (or outright bug) in Windows that is exposed by my particular configuration:
- I had a domain account COMPANY_DOMAIN\ashepherd
- The remote server has a local account SERVER_NAME\ashepherd
I am logged into my client machine using the domain account, but am attempting to access the server using it's LOCAL account. The two accounts have the same account name, but happen to have different passwords.
As an experiment, I modified SERVER_NAME\ashepherd so both accounts have the same password. And now everything works without any lockouts.
To get the credentials, I was typing in
$cred = (get-credential)
Then I was just typing in ashepherd, instead of SERVER_NAME\ashepherd.
I don't think this is the way it should be. Is this known behavior?