Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, February 18, 2013 8:44 AM
Hi,
I want to remote execute a command on cmd line on remote computer using Win32_Process and be able to read the output of the command execution.
For example if I have somthing.exe / dir (a dos command) in path of remote machine "R". I want to be able to run the program on remote machine from machine "X" and read the output from machine "X" .
Any help is greatly appreciated. Thanks in advance.
$command = "ipconfig/all"
$cmd = "CMD.EXE /c "+$command
$newproc = Invoke-WmiMethod -class Win32_process -name Create -ArgumentList ($cmd) -ComputerName "remotepc"
But the output what i am getting is
_GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 2
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ProcessId : 4152
ReturnValue : 0
ReturnValue : 0 which means...it got successfully completed on the remote machine.
But i want the output on my machine, from where i am executing.
Thanks
Azam
Thanks Azam When you see answers and helpful posts, please click Vote As Helpful,
All replies (4)
Monday, February 18, 2013 1:43 PM âś…Answered | 1 vote
You can't using Win32_process to get output directly.Only one way, using temporary file on remote pc:
$command = "ipconfig/all > C:\temp\result.txt"
$cmd = "CMD.EXE /c "+$command
Invoke-WmiMethod -class Win32_process -name Create -ArgumentList $cmd -ComputerName "remotepc"
Get-Content \\remotepc\C$\temp\result.txt
Monday, February 18, 2013 8:51 AM | 2 votes
1) PsExec
Using PowerShell and PsExec to invoke expressions on remote computers
2) PSRemoting
Invoke-Command -ComputerName remote -ScriptBlock {ipconfig /all}
3) Or use WMI to get infrom about Net
Get-WMIObject Win32_NetworkAdapter -Comp remotepc
Win32_NetworkAdapter
Win32_NetworkConnection
Win32_NetworkProtocol
Win32_NetworkClient
Win32_NetworkLoginProfile
Win32_NetworkAdapterConfiguration
Win32_NetworkAdapterSetting
Monday, February 18, 2013 1:29 PM
Kazun.
Thanks for the reply.
I am facing challenges while excuting using psremoting/psexec ....as we have mixed OS...win2k,win2k3 and win2k8...and feasibility of using ps2 is not there.
Can you please help me pulling it through invoking wmi win32_Process.
I am trying to pull the HBA details using hbacmd.exe on the remote machine.
$command = "ipconfig/all"
$cmd = "CMD.EXE /c "+$command
$newproc = Invoke-WmiMethod -class Win32_process -name Create -ArgumentList ($cmd) -ComputerName "remotepc"
This is working good enough...only thing is to get the output on the computer from where i am executing.
Appreciate your help.
Thanks Azam When you see answers and helpful posts, please click Vote As Helpful,
Monday, February 18, 2013 3:05 PM | 1 vote
Thanks Kazun,
Above worked ...just added start-sleep -s 2 between invoke and get-content. else the output was coming blank.
$command = "ipconfig/all > C:\temp\result.txt"
$cmd = "CMD.EXE /c "+$command
Invoke-WmiMethod -class Win32_process -name Create -ArgumentList $cmd -ComputerName "remotepc"
Start-sleep -s 2
Get-Content \remotepc\C$\temp\result.txt
Thanks Azam When you see answers and helpful posts, please click Vote As Helpful,