Grant read permission for MSysObjects Grant read permission for MSysObjects powershell powershell

Grant read permission for MSysObjects


There are two issues you must address:

  1. Your code will use the Access security account "Admin" when interacting with the Access ACCDB database. Other Access security accounts are only available if you have implemented Access user-level security (ULS), but that feature is only available for MDB format databases. Therefore, with ACCDB, you can't GRANT anything to any account other than "Admin".

  2. You must include the location of the "System database" in your connection string.

If you don't know where to find the System database, open Access and check the output from this statement in the Immediate window. (Ctrl+g will open the Immediate window)

Debug.Print Application.DBEngine.SystemDb

My System database is C:\Users\hans\AppData\Roaming\Microsoft\Access\System1.mdw Substitute yours in the code example below.

I'm not really proficient with Powershell, but this example ran without error for me. (Be sure to change both $Db and $SystemDb.)

$ScrUsr = $(whoami)Write-Host $ScrUsr$cmd = "GRANT SELECT ON MSysObjects TO Admin;"Write-Host $cmdFunction Invoke-ADOCommand($Db, $SystemDb){  $connection = New-Object -ComObject ADODB.Connection  $ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$db;Jet OLEDB:System database=$SystemDb;"  Write-Host $ConnectionString  $connection.Open($ConnectionString)  $discard = $connection.Execute($cmd)  $connection.Close()} $Db = "C:\Users\hans\AccessApps\Sample.accdb"$SystemDb = "C:\Users\hans\AppData\Roaming\Microsoft\Access\System1.mdw"Invoke-ADOCommand -db $Db -SystemDb $SystemDb