I have a master and a sub script as PowerShell scripts. From the Sub PowerShell script, a SQL file is called. I am looking to pass in a variable to the SQL from Master script through the sub script. I can see it is coming to sub script but is not coming to SQL file.
Master Script has below;
Invoke-Command -ComputerName $server_temp -FilePath E:\PshellScripts\ErrorChecks_Sub.ps1 -argumentlist $batchname
Sub script has below;
$password = get-content E:\SQL\config\access.txt
$sqlParameters = "powerShellVar='$args'"
& E:\Oracle\BIN\sqlplus.exe schema1/$password@env1 @E:\env1\SQL\Batch_Jobs_Error_Check.sql -Variable $sqlParameters
Batch_Jobs_Error_Check.sql has below;
set echo off
set doc off
set pagesize 9999
set linesize 300
set feedback off
set verify off
set pause off
set flush off
set heading on
set newpage none
set termout off
set trimspool on
spool E:\logs\Batch_Jobs_Details\Batch_Error.DTA;
select *
from batch_error where batch_name like '$($powerShellVar)';
spool off;
exit
In the above sample, file name is hard coded. I would prefer if the filename can be dynamically assigned as the '$($powerShellVar)'_error.dta
Could you have a look and let me know please?
Thanks, Mary