Powershell Oracle connection using SecureStore

21 Views Asked by At

I need to be able to run a script and get the Get-Secret and run $sqlQuery on same line

This works:

Get-Secret -Vault DBASecretStore -Name dbautil -AsPlainText | sqlplus dbautil/  

But I need to be able to run $sqlQuery too and this doesn't work. I need to be able to connect then run the @sqlQuery

    $sqlQuery = @"
        SET LINESIZE 200
        SELECT name 
        FROM v`$database;
"@
$sqlQuery | Get-Secret -Vault DBASecretStore -Name myuser -AsPlainText | sqlplus myuser/  > dbname.log
1

There are 1 best solutions below

0
Mathias R. Jessen On

Write the query to disk and reference the script file in the command:

$sqlQuery |Set-Content temp_query.sql
Get-Secret -Vault DBASecretStore -Name dbautil -AsPlainText | sqlplus dbautil/ "@$PWD/temp_query.sql"
Remove-Item temp_query.sql