1

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.

0

That "EOF" string you're using up there on the Linux thing is not and character. You're using a "here document". The EOF is just a string for perl to know where your here document ends. I always use something that is unlikely to be found IN the here document, like fInI.

Powershell. Yeah. Nightmare for us *nix folks.

0

Im don't know too much about the Linux commands. You could try

$UserName = "username"
$Password = "password"
$tnsalias = "tnsalias"
$SqlQuery =
@'
set feedback off
select username from dba_users;
exit
'@

Invoke-SSHCommand -Command "$SqlQuery |
 sqlplus $username/$password@$tnsalias"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.