1

In theory I feel this should kinda be simple. Basically I need a query in access to be run every hour or so through powershell, and then if a certain condition in the query is met I need an email sent.

The email, and the query is simple enough, but I don't know how I can get powershell to query access, and I'm unsure if I can get it the query to run every hour. But if I can just get powershell to run a query on access I'll be happy enough.

2

2 Answers 2

2

if I can just get powershell to run a query on access I'll be happy enough

The "ACE.psm1" module referenced in the other answer looks useful, but if you prefer to "roll your own" code for database access you could use something like this:

$connStr = @"
Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=C:\Users\Public\Database1.accdb
"@
$con = New-Object System.Data.OleDb.OleDbConnection $connStr
$con.Open()
$cmd = New-Object System.Data.OleDb.OleDbCommand "SELECT * FROM Clients", $con
$rdr = $cmd.ExecuteReader()
while ($rdr.Read())
{
    Write ("{0}, {1}" -f $rdr["LastName"], $rdr["FirstName"])
}
$rdr.Close()
$con.Close()
Sign up to request clarification or add additional context in comments.

Comments

1

running some scriptblock hourly:

$command =  {

    $trigger = New-JobTrigger -RepetitionInterval (New-TimeSpan -Minutes 60) -RepeatIndefinitely `
    -At (get-date) -Once

    $job = Register-ScheduledJob -Name 'Test' -Trigger $trigger -ScriptBlock {
        (Get-Date).DateTime | Out-File D:\test.txt -Append
    } 
}
Start-Process -FilePath powershell.exe -ArgumentList "-noprofile -command $Command" -Verb runas

have a look the ACE module here:

Use ACE Drivers and PowerShell to Talk to Access and Excel

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.