Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. Add-Type -Path "C:\Oracle\product\12.2.0\client32\odp.net\managed\common\Oracle.ManagedDataAccess.dll"
  2. $date = Get-Date -format "yyyyMMdd"
  3. $username = "advanced"
  4. $password = Get-Content "F:\SQL Sondage\password.txt"
  5. $datasource = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=GAZ-ODB-003.egd.enbridge.com)(PORT=1530))(CONNECT_DATA=(SERVICE_NAME=GCIPRD.egd.enbridge.com)));User ID=advanced;Password=xxxxxxxx;Min Pool Size=5;"
  6. $query = Get-Content "F:\SQL Sondage\Queries\CO-VIG.sql"
  7. $connectionString = 'User Id=' + $username + ';Password=' + $password + ';Data Source=' + $datasource
  8. $connection = New-Object Oracle.ManagedDataAccess.Client.OracleConnection($connectionString)
  9. $connection.open()
  10. $command = New-Object Oracle.ManagedDataAccess.Client.OracleCommand
  11. $command.Connection = $connection
  12. $command.CommandText = $query
  13. $ds = New-Object system.Data.DataSet
  14. $da = New-Object Oracle.ManagedDataAccess.Client.OracleDataAdapter($command)
  15.  
  16. if($ds.Tables[0] == 0){
  17. return Add-Content F:\SQL Sondage\Output\Preformat\$date\CO-VIG-$date-2.csv "header1,header2,header3,header4"
  18. } else {
  19. [void]$da.fill($ds)
  20. return $ds.Tables[0] | SELECT * | Export-CSV "F:\SQL Sondage\Output\Preformat\$date\CO-VIG-$date-2.csv" -NoTypeInformation -Encoding UTF8
  21. }
  22. $connection.Close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement