I have a RHEL server with Oracle 10G installed. I need to write a powershell script to query my database and get the output. I have imported Posh-SSH module and am able to connect to my RHEL server and execute commands using Invoke-SSHCommand
however, i need help in executing sqlplus command using my Invoke-SSHCommand
. Normally, we can achieve this in perl using EOF but, am not able to find any way to get this done using powershell.
code for Perl using EOF:
$command="export ORACLE_SID=database
sqlplus -S user/password<< EOF
set feedback off
select username from dba_users;
EOF"
My Powershell code:
$command="export ORACLE_SID=database
sqlplus -S user/password<< EOF
set feedback off
select username from dba_users;
EOF"
$result = Invoke-SSHCommand -Index 0 -Command $command
Write-Output $result
My Output for Powershell:
Host : XX.XX.XXX.XXX
Output :
ExitStatus : 127
I guess, EOF characters are understood by Powershell.
Can anyone help me in converting this to powershell?. I've tried many ways but all in vain. Everytime i execute this code, I get Exit code: 127.