Get-WmiObject -ComputerName -AsJob Failed

Hi!

This is what i executed:
Get-WmiObject win32_operatingsystem -ComputerName zhou -Credential azhou -AsJob

It gives me an error that “access denied: 0x80070005(E_ACCESSDNIED)”

Both of two version of system is Win11 Pro, 22H2, 22621.2134

I am confused why it happened

My guess is it’s a sort of double-hop being a job and a remote connection. Try this instead

$job = Start-Job -ScriptBlock {Get-WmiObject win32_operatingsystem -ComputerName zhou} -Credential azhou

$job | Receive-Job -AutoRemove -Wait

I’d recommend anyway NOT to use Get-WmiObject anymore. Instead use

:man_shrugging:t3:

1 Like

You know, Olaf, you are correct. I was being lazy. Thank you for calling me out.

$job = Start-Job -ScriptBlock {Get-CimInstance win32_operatingsystem -ComputerName zhou} -Credential azhou

$job | Receive-Job -AutoRemove -Wait
1 Like
$job = Start-Job -ScriptBlock {Get-WmiObject win32_operatingsystem -ComputerName zhou -Credential azhou}
$job | Receive-Job -AutoRemove -Wait

It works !

Maybe only when two of PC are in the same domain, "Get-WmiObject -ComputerName -AsJob " would work.
Thank you for your answer !

Thanks for your answer !
I am executing that command just like what the book I am learning shows ,but it can’t work.So I am
very confused.That‘s the last command I doesn’t success to execute .I hope I can figure out one day .

What book is it? If it’s a kind of up to date it should at least recommend to use Get-CimInstance instead of Get-WmiObject

You should always read the complete help for the cmdlets you’re about to use to learn how to use them. In the case of Get-WmiObject it is the first sentence of the description paragraph where you can read …

Starting in PowerShell 3.0, this cmdlet has been superseded by Get-CimInstance .

And BTW:
PowerShell version 3.0 has been released 2012 - that’s more than 10 Years ago. :wink:

The book is “Learn Windows PowerShell in a Month of Lunches (Third Edition)” written by Don Jones and Jeffety Hicks .It is published in December 2016.

Click here to read the book

And BTW:
Maybe 10 years ago the situation was just like now !

Maybe only when two of PC are in the same domain, "Get-WmiObject -ComputerName -AsJob " would work.That is the explain I give to make me not feel so confused .

No I’m 99.9998% confident this is not the case. The issue is trying to pass custom credentials through a job and then a remote session. If the calling account (even in workgroup) had rights, then it would work fine. With the Start-Job command the entire scriptblock is running as the specific credentials, it’s not trying to pass them again. This is my interpretation of the test results. Case in point, my PC at home and my children’s computers all have an identical user account for me so I can use remoting without specifying credentials. This is a workgroup config. The Get-WmiObject and Get-CimInstance both work without specifying credentials manually as well as when running the scriptblock with Start-Job. However trying to pass these same credentials through Get-WmiObject as a job hit the same issue you did.

1 Like