I have a multi-user Access database which is compacted daily using a powershell script. This script can't compact the database if there are still users logged in. If there is a user logged in, I would like be able to idenify the user(s) who forgot to logout of the database and remind them to log out at the end of the day.
If I were to write this in VB it would work like this:
Dim cn as ADODB.Connection
Dim rs as ADODB.Recordset
cn.open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=...mdb")
Set rs = cn.OpenSchema(adSchemaProviderSpecific, ,"{947bb102-5d43-11d1-bdbf-00c04fb92675}")
Then loop through the recordset and get the information I want.
What I would like to do is translate this to PowerShell so it can run with the compact script. I have tried the following:
$objCon = New-Object -ComObject ADODB.Connection
$objRs = New-Object -ComObject ADODB.Recordset
$objCon.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=...mdb")
$objRs= $objCon.OpenSchema([ADODB.SchemaEnum]::adSchemaProviderSpecific,$null,'{947bb102-5d43-11d1-bdbf-00c04fb92675}')
$objRs.MoveFirst()
Then loop through the recordset and find the information I need.
The ps code errors out on the OpenSchema line with:
Exception calling "OpenSchema" with "3" argument(s): "Object or provider is not capable of performing requested operation." At FindUsers.ps1:8 char:27 + $objRs= $objCon.OpenSchema <<<< ([ADODB.SchemaEnum]::adSchemaProviderSpecific,$null,'{947bb102-5d43-11d1-bdbf-00c04fb92675}') + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
The script won't execute if I remove the middle $null variable or replace it with '', and I don't know if the command is translated from VB to powershell correctly. I've searched on Google and SO and haven't found any solutions. What do I need to do to use the OpenSchema command?