Skip to content

Instantly share code, notes, and snippets.

@mtcoffee
Created September 10, 2016 15:53
Show Gist options
  • Save mtcoffee/ace1461515a341e95c792d8b59afdf43 to your computer and use it in GitHub Desktop.
Save mtcoffee/ace1461515a341e95c792d8b59afdf43 to your computer and use it in GitHub Desktop.
Use PowerShell to query multiple databases
#This script requires Powershell, sqlplus aka Oracle command line client and tnsname resolution of your target databases
#A typical use case would be to find the lock status of an account in multiple databases
$databases = @("fndev", "fntst")
$credential = Get-Credential
$username = $credential.GetNetworkCredential().username
$password = $credential.GetNetworkCredential().password
if (!$password) { Write-Host "password is null"; Exit }
foreach ($db in $databases)
{
$sqlQuery = @"
set NewPage none
set heading off
set feedback off
select count(*) from psoprdefn where oprid='PS' and ACCTLOCK = '0';
exit
"@
write-host -nonewline -f yellow $db
$sqlQuery | sqlplus -silent $username/$password@$db | write-host
write-host
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment