Get status of a process started by Invoke-WmiMethod

New to PowerShell, but loving the fact that I can do so much so fast :)

In any case, I run the remote process in a PowerShell script as follows:

$compname = "MY-PC" $myinstallcmd = "c:\install\myprog.exe /s" $proc = Invoke-WmiMethod -class Win32_Process -name Create -ArgumentList ($myinstallcmd) -ComputerName $compname 

On most computers I tried, the Invoke-WmiMethod cmdlet works fine, but it hangs on one PC. What I'm looking for now is to get the status of a running process, and if it hangs up, kill it and write it to kill, and then go.

I found a possible method for this in the message Starting the process remotely in Powershell, getting% ERRORLEVEL% on Windows - however, when I try to do Register-WmiEvent in the $ proc.ProcessId process, I get the terrible error 0x80070005 (E_ACCESSDENIED) ... I am running PowerShell host as a domain administrator.

Can anyone suggest a way that I can get status in the process that I started and be able to take action based on the status?

Thanks!

+4
source share
1 answer

Update: I think you are missing the credentials of the remote system:

Try passing credentials to the remote system using the -Credential parameter. This takes a PSCredential object and therefore you can do something like:

 $cred = Get-Credential Register-WMIEvent -Credential $cred <and other parameters here> 

Check if any of the following errors are resolved:

0x80070005 (DCOM ACCESS_DENIED) This error occurs when the connected user is not recognized or is in some way restricted by the remote server (for example, the user may be blocked). This happens most often when accounts are in different domains. Recent WMI security changes may also cause this error:

  • Empty passwords previously allowed are not allowed on Windows XP and Windows Server 2003.

  • WMI does not allow asynchronous callbacks to a Windows 98 client. A call of type SWbemServices.ExecNotificationQueryAsync from a computer running Windows 98 to a computer running Windows XP will result in an Access Denied error returned to the Windows 98 computer.

  • Access settings for the DCOM configuration can be changed.

  • If Windows XP is installed on the target computer, the Forceguest value under the registry key HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Lsa can be configured to force a disconnection of the guest account (the value is zero).

Source: http://technet.microsoft.com/en-us/library/ee692772.aspx

0
source

Source: https://habr.com/ru/post/1344662/


All Articles