locked
How to read .dbf files using powerhsell RRS feed

  • Question

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

    Thanks
     

    student
    • Changed type Marco Shaw Wednesday, December 16, 2009 1:05 AM this is a question
    Tuesday, December 15, 2009 12:17 AM

Answers

  • 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
    • Proposed as answer by Marco Shaw Wednesday, December 16, 2009 1:05 AM
    • Marked as answer by Mervyn Zhang Thursday, December 17, 2009 7:11 AM
    Tuesday, December 15, 2009 4:00 PM
  • 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;


    • Proposed as answer by Marco Shaw Wednesday, December 16, 2009 1:05 AM
    • Marked as answer by Mervyn Zhang Thursday, December 17, 2009 7:11 AM
    Tuesday, December 15, 2009 3:46 AM

All replies

  • 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 2:00 AM
  • 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;


    • Proposed as answer by Marco Shaw Wednesday, December 16, 2009 1:05 AM
    • Marked as answer by Mervyn Zhang Thursday, December 17, 2009 7:11 AM
    Tuesday, December 15, 2009 3:46 AM
  • 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
    • Proposed as answer by Marco Shaw Wednesday, December 16, 2009 1:05 AM
    • Marked as answer by Mervyn Zhang Thursday, December 17, 2009 7:11 AM
    Tuesday, December 15, 2009 4:00 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:
    Tuesday, December 15, 2009 5:05 PM
  • Thanks Sir, it works....
    student
    Tuesday, December 15, 2009 9:21 PM
  • 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;"
    


    Tuesday, October 18, 2011 7:16 AM
  • 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()

    Wednesday, March 2, 2016 2:22 PM