0
votes

I am simply trying to execute a program on a remote machine using a pssession:

Invoke-Command -Session $session -ScriptBlock {cd c:\ powershell; Invoke-WmiMethod -path win32_process -name create -argumentlist $arra y}

My array of arguments looks like this:

$array
c:\powershell\sqbconverter.exe
d:\Restore\xxxx\FULL_(local)_xxxx_PROD_20131016_230001.sqb
D:\Restore\xxxx\full\Restore_xxxx_full.bak
xxxxxx

This is the result:

PSComputerName     : hostname1
RunspaceId         : 92656a18-ca0f-4684-aff2-086f109fce59
PSShowComputerName : True
__GENUS            : 2
__CLASS            : __PARAMETERS
__SUPERCLASS       :
__DYNASTY          : __PARAMETERS
__RELPATH          :
__PROPERTY_COUNT   : 2
__DERIVATION       : {}
__SERVER           :
__NAMESPACE        :
__PATH             :
ProcessId          :
ReturnValue        : 21

I'm not sure how to debug what exactly is happening on the remote machine but I am not getting my desired output (the exe should create an output file). Any help would be much appreciated, thank you.

1
Why are you running Invoke-WmiMethod via Invoke-Command -Session instead of running it directly against the remote host (Invoke-WmiMethod -Computer ...)?Ansgar Wiechers

1 Answers

0
votes

You need to inject your $array into the scripblock you pass to Invoke-Command e.g.:

Invoke-Command -Session $session -ScriptBlock {param($arr)
    cd c:\ powershell
    Invoke-WmiMethod Win32_Process -Name create -ArgumentList $arr} -Arg $array