0

I am trying to run the following command in power shell but it keeps giving me error at the double back slash character.. what do i do!! I saw other forums and this yntax works fine for them!

$combined="C:\tools\PsExec.exe \\computer cmd.exe"
PS C:\Users\Desktop\initialutility\initutil_v2> Invoke-Expression $combined

At :line:1 char:20
+ C:\tools\PsExec.exe  <<<< \\computer cmd.exe

I substituted \computer with \x.x.x.x (i.e Ip address)..still no use.. Please help!

py_newbie
  • 136
  • 13

1 Answers1

1

I believe your problem lies elsewhere as double slashes work fine e.g.:

PS> $command = "c:\bin\psexec.exe \\genericpc1 hostname.exe"
PS> iex $command

PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com


GENERICPC1
hostname.exe exited on genericpc1 with error code 0.

I would try running psexec.exe outside the context of Invoke-Expression and get that working first. Another issue with using psexec is that it uses your credentials if you don't specify any credentials. That means, your credentials need to work on the remote system.

Other requirements, from an article on PsExec are:

PsExec's ability to run processes remotely requires that both the local and remote computers have file and print sharing (i.e., the Workstation and Server services) enabled and that the default Admin$ share (a hidden share that maps to the \windows directory) is defined on the remote system.

... impersonates the account from which you run PsExec on the local system. Impersonation is somewhat restricted from the perspective of security—the remote process doesn't have access to any network resources, even those that your account typically would be able to access. If the account in which you're running doesn't have local administrative privileges on the remote system, the process you want to run requires access to network resources, or you want to run a process in a different account, then use PsExec's -u switch to provide an alternative account name. share (a hidden share that maps to the \windows directory) is defined on the remote system.

Keith Hill
  • 194,368
  • 42
  • 353
  • 369