Geo
Geo

Reputation: 144

Unable to run sqlplus with PsExec from PowerShell

I cannot run a sqlplus query on a remote computer using PowerShell and PsExec.

This is my code:

$psexec = "PsExec64.exe"
$computername = "server1"
$usr = "user"
$pwd = "password"
$command = "cmd /c"
$sqltool = "sqlplus.exe"
$parameters = "@echo select * from TEST.T1 where C1 = 1; | $sqltool -s / as sysdba"
& $psexec -accepteula \\$computername -n 15 -u $usr -p $pwd $command $parameters | Out-Null

I get the error message:

PS C:\> & $psexec -accepteula \\$computername -n 15 -u $usr -p $pwd $command $parameters | Out-Null
PsExec64.exe : The system cannot find the path specified.
At line:1 char:1
+ & $psexec -accepteula \\$computername -n 15 -u $usr -p $pwd $command  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (The system cann...path specified.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

When i run the command without variables it works fine:

PsExec64.exe -accepteula \\server1 -n 15 -u user -p password cmd /c ("@echo select * from TEST.T1 where C1 = 1; | $sqltool -s / as sysdba")

Can somebody please help me clarify the issue?

Upvotes: 0

Views: 589

Answers (1)

lit
lit

Reputation: 16236

Here is the quoting I needed to do to get something simple to run.

$psexec = 'PsExec64.exe'
$computername = 'HOST001'
$usr = "DOMAIN\username"
$pwd = "password"
$sqltool = "sqlplus.exe"
$parameters = "@echo select 'now' from DUAL; `| $sqltool -S dbuser/dbpass@DBHOST"

& "$psexec" -accepteula -nobanner \\$computername -n 15 -u $usr -p $pwd cmd /c "$parameters"

Upvotes: 2

Related Questions