Posted on Leave a comment

PowerShell Connect to MSAccess

$adOpenStatic = 3
$adLockOptimistic = 3
$adStatusOpen = 1
$sql = "Select * from dispatch;"
$cstr = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = c:tempmydata.mdb; Jet OLEDB:Database Password=mypass;"

$conn = New-Object -comobject ADODB.Connection
$rs = New-Object -comobject ADODB.Recordset

$conn.Open($cstr)

if ($conn.State -eq $adStatusOpen)
{
$rs.Open($sql, $conn, $adOpenStatic, $adLockOptimistic)

if ($rs.State -eq $adStatusOpen)
{
$rs.MoveFirst()

while (!$rs.EOF)
{
$rs.Fields.Item(1).Value;
$rs.MoveNext()
}
$rs.Close()
}

$conn.Close()
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.