Output of a DB Query as Email using Powershell [message #547549] |
Wed, 14 March 2012 12:11 |
kmsalih
Messages: 197 Registered: March 2006
|
Senior Member |
|
|
Hello All,
Currently i am writing a code using powershell to query from Oracle Database 11g Release 2.
I got a code by searching google.
function Get-OLEDBData ($connectstring, $sql) {
$OLEDBConn = New-Object System.Data.OleDb.OleDbConnection($connectstring)
$OLEDBConn.open()
$readcmd = New-Object system.Data.OleDb.OleDbCommand($sql,$OLEDBConn)
$readcmd.CommandTimeout = '300'
$da = New-Object system.Data.OleDb.OleDbDataAdapter($readcmd)
$dt = New-Object system.Data.datatable
[void]$da.fill($dt)
$OLEDBConn.close()
return $dt
}
$connString = "password=assword;User ID=SYSTEM;Data Source=XE;Provider=OraOLEDB.Oracle"
$qry= "SELECT * FROM HR.DEPARTMENTS"
./Get-OLEDBData $connString $qry
is it required to create a DataSource using odbc32.cpl which points to the Oracle Database.
Also if you have a code for emailing the output of a query please post.
Thanks,
Salih KM
|
|
|