Created
September 10, 2016 15:53
-
-
Save mtcoffee/ace1461515a341e95c792d8b59afdf43 to your computer and use it in GitHub Desktop.
Use PowerShell to query multiple databases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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