Home > Enterprise >  How to specify local domain with Invoke-WmiMethod
How to specify local domain with Invoke-WmiMethod

Time:04-01

I am trying to connect to a remote computer using a local administrator account via WMI using the powershell cmdlet Invoke-WmiMethod.

I can get it to work using a domain account. However, when I try to use a local account, it assumes that I want to use an AD account. The local account does exist on the remote computer.

I'm generating the PSCredential object with the following command:

$cred = Get-Credential account01

I'm passing the credential object to Invoke-WmiMethod with this command:

Invoke-WmiMethod -Path Win32_Process -Name Create -ArgumentList "cmd.exe /c echo hello world" -ComputerName adcomputer -Credential $cred

When I look at the event viewer logs on the remote computer, it shows that it is attempting to use ADDOMAIN\account01 instead of attempting to log in using the local account database.

Attempting to enter ".\account01" to signify the domain is the local computer does not work, I get the following error after trying to create the credential object:

enter image description here

Is there any way to use this cmdlet to connect to a remote computer using a local administrator account (on remote host)?

CodePudding user response:

The specific error/validation hint you receive is part of the credential GUI component used by Windows PowerShell's Get-Credential implementation.

That means you can work around it by manually constructing your credential object:

$cred = [pscredential]::new('.\account01', $(Read-Host 'Input password' -AsSecureString))
  • Related