Share via


How to read .dbf files using powerhsell

Question

Tuesday, December 15, 2009 12:17 AM

is there any way to read dbase  .dbf files from powerhsell.

Thanks

 

student

All replies (7)

Tuesday, December 15, 2009 3:46 AM ✅Answered

I think if you port the code to powershell from the .net method that Marco linked to and use this connection string you can probably get it working:

Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=c:\mydbpath;


Tuesday, December 15, 2009 4:00 PM ✅Answered | 2 votes

Using the connectionstring from Tome Tanasovski (assuming it is right, I can not test it), the PowerShell script to get a table from it might look like this :

$ConnString = "Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=c:\mydbpath;"
$Conn = new-object System.Data.OleDb.OleDbConnection($connString)
$conn.open()

$cmd = new-object System.Data.OleDb.OleDbCommand("select * from MyTable",$Conn)
$da = new-object System.Data.OleDb.OleDbDataAdapter($cmd)
$dt = new-object System.Data.dataTable 
$da.fill($dt)
$dt

h.t.h.

Greetings MOW


Tuesday, December 15, 2009 2:00 AM

Sorry, I don't know much about dbase...  You'll need something to use to have PowerShell interface with to handle the dbase files.

This might look promising:
http://forums.devx.com/archive/index.php/t-56825.html


Tuesday, December 15, 2009 5:05 PM

I actually got that conn string from connectionstrings.com.  It's a quick place to look them up.

Actually you should look at the dbf foxpro page.  It looks like you can connect to a dbf with a few providers, including Jet.  It may depend on the version of the database you are using:

http://www.connectionstrings.com/dbf-foxpro


Tuesday, December 15, 2009 9:21 PM

Thanks Sir, it works....student


Tuesday, October 18, 2011 7:16 AM

Don't know why that connection string didn't work for me, but this one worked:

$ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydbpath;Extended Properties=dBASE IV;"

Wednesday, March 2, 2016 2:22 PM

i was able to connect to a dbf file when launching 32bit powershell and using this: 

$conn = new-object System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\dbf;Extended Properties=dBASE IV;User ID=;Password=;")
$conn.open()