Script connects to the .MDB file using user DSN named “MS Access Database” pointing to the .MDB file and then queries the specified columns.
[code language=”powershell”]
$adOpenStatic = 3
$adLockOptimistic = 3
$userName = $env:USERNAME
$newDbPath = "C:\Temp\$userName\DPW"
$connectionString = "DSN=MS Access Database;"
$sourceQuery = "Select * From Connection"
$objConnection = New-Object -com "ADODB.Connection"
$objRecordSet = New-Object -com "ADODB.Recordset"
$objConnection.Open($connectionString)
$objRecordset.Open($sourceQuery, $objConnection, $adOpenStatic, $adLockOptimistic)
$objRecordset.MoveFirst()
While ($objRecordset.EOF -ne $True) {
ForEach ($column in "ConnectString", "FilePath", "BackupPath") {
$objRecordset.Fields.Item("$column").Value
}
$objRecordset.MoveNext()
}
$objRecordset.Close()
$objConnection.Close()
[/code]
.