This article describes how to create a service to launch a Powershell script to connect to SQL plus in a remote Windows system
This is based on article
The TCP Service must be configured in the following way for the Powershell execution to work
Note that the arguments to define in the Client App command line are as follows for the Powershell version as of the writing of this KB (November 2024)
cmd /c start powershell -NoExit -ExecutionPolicy Bypass "C:\tmp\sqlplus\PAMService.ps1" -user "<User>" -password "<Password>" -localip "<Local IP>" -firstport "<First Port>"
The switches may vary or change in the future versions of Powershell, so some tweaking may be necessary
The Powershell script, PAMService.ps1 which does the connection is given in what follows:
param(
[string]$user,
[string]$password,
[string]$localip,
[string]$firstport
)
# Display the parameters for verification
#Write-Host "Connecting with:"
#Write-Host "User: $user"
#Write-Host "Local IP: $localip"
#Write-Host "Port: $firstport"
# Construct SQL*Plus connection string
$connectionString = "$user/$password@$localip`:$firstport"
# Path to sqlplus
$sqlplusPath = "C:\tmp\sqlplus\instantclient_23_5\sqlplus.exe"
# Start SQL*Plus with connection string
& $sqlplusPath $connectionString
Read-Host "Press Enter to exit"
Please note that with this service definition, no session recording will be possible as the Application Protocol is set to Disabled