Use Powershell to save a datatable as a csv
csv, datatable, powershell
Solution
this should do it I think:
$ds = New-Object System.Data.DataSet
$da.Fill($ds) >$null| Out-Null
$ds.Tables[0] | export-csv tofile.csv -notypeinformation
Problem
There has to be an easy way to do this. I have a Powershell script which connects to a database and I want to save the resulting datatable as a CSV. Here is the code so far: ``` $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() ```