Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param($tnsnamesPath = 'c:\tns\tnsnames.ora',$username = 'user',$password = 'gotmehere', $connectionName = 'mustard', $query = 'Select sysdate from dual')
- $simplySQLPath = (Get-Module -ListAvailable simplySQL).ModuleBase
- if($simplySQLPath -and (test-path $tnsnamesPath -PathType Leaf) -and (![string]::IsNullOrEmpty($node)))
- {
- [System.Reflection.Assembly]::LoadFile("$simplySQLPath\DataReaderToPSObject.dll") | OUT-NULL
- Import-Module SimplySql -Force
- $parsedTN = (get-content $tnsnamesPath -raw) -replace '(.*\=.*|\n.*\=)(.*|\n.*)\(DESCRIPTION*.\=' ,'Data Source = (DESCRIPTION ='
- $splitTN = $parsedTN -split '(?=.*Data Source = \(DESCRIPTION \=)'
- $tnsnames = $splitTN |?{$_ -like "*$connectionName*"}
- $connstring = "$tnsnames;User Id=$username;Password=$password"
- try
- {
- Open-OracleConnection -ConnectionString $connstring -ConnectionName $connectionName
- $result = Invoke-SqlQuery -ConnectionName $connectionName -Query "$SQLQuery"
- Close-SqlConnection -ConnectionName $connectionName
- }
- catch
- {
- $_.exception
- }
- }
- Else
- {
- if(!(test-path $tnsnamesPath -PathType Leaf -ErrorAction Ignore))
- {
- Throw "Check TNSnamesPath: $tnsNamesPath"
- }
- else
- {
- Throw "Exeception SIMPLYSQL not found in module Path $($env:PSModulePath)"
- }
- }
- $result
Add Comment
Please, Sign In to add comment