必须有一个简单的方法来做到这一点。我有一个连接到数据库的 Powershell 脚本,我想将生成的数据表保存为 CSV。这是到目前为止的代码:
$connString = "Provider=msdaora;Data Source=MyDatabase;User Id=test;Password=test
$qry = "select * from employees"
$OLEDBConn = New-Object System.Data.OleDb.OleDbConnection($connString)
$OLEDBConn.open()
$readcmd = New-Object system.Data.OleDb.OleDbCommand
$readcmd.Connection = $OLEDBConn
$readcmd.CommandTimeout = '300'
$readcmd.CommandText = $qry
$da = New-Object system.Data.OleDb.OleDbDataAdapter($readcmd)
$dt = New-Object system.Data.datatable
[void]$da.fill($dt)
$OLEDBConn.close()