question

KeiKoo-6956 avatar image
0 Votes"
KeiKoo-6956 asked BijuPhilipJacob-4158 published

Command to start an MS-Access-Database with security workgroup attribute with a Powershell Script

Hi,

I'm new to Powershell scripting and I'm currently writing my first script.
I have a problem for which I haven't found a solution even after a long search on the web.Maybe someone here can put me on the right track.

In my script I wanna start an MSAccess database, with the /wrkgrp attribute.
Unfortunately, I can't get this running with a Powershell command.

A few informations:
The command line used in a local desktop shortcut to start the Database with secure workgroup:

"C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" "\\SRV2013-01.db.net\DBs\Database.mdb" /wrkgrp "\\SRV2013-01.db.net\DBs\WGs\MyWorkgroup.mdw"

I can also enter this command line in the old CMD console and starting the database.

In Powershell I have already made several attempts, first with the "Invoke-Item" command:

 Invoke-Item "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" "\\SRV2013-01.db.net\DBs\Database.mdb" /wrkgrp "\\SRV2013-01.db.net\DBs\WGs\MyWorkgroup.mdw"

and then with the "Start-Process" command:

 Start-Process "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" "\\SRV2013-01.db.net\DBs\Database.mdb" /wrkgrp "\\SRV2013-01.db.net\DBs\WGs\MyWorkgroup.mdw"

So far without success.

As an alternative I used the following command that use the old CMD console.
This works, but I would like to change this code line to a "clean" Powershell command, without using the old CMD console command.

 CMD /c "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" "\\SRV2013-01.db.net\DBs\Database.mdb" /wrkgrp "\\SRV2013-01.db.net\DBs\WGs\MyWorkgroup.mdw"

I hope I was able to describe my concern clearly and now I hope for an interesting exchange.

Many Thanks

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
1 Vote"
RichMatheisen-8856 answered RichMatheisen-8856 edited

Why not keep it simple and use the "Call" operator?

 & "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" "\\SRV2013-01.db.net\DBs\Database.mdb" /wrkgrp "\\SRV2013-01.db.net\DBs\WGs\MyWorkgroup.mdw"


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Rich,

Many thanks for this post!

For a newby as mee, this simple command looks simply genius ;)
As mentioned, I'm new in Powershell and didn't know that I can call this entire command string by this way.
This is already a nice solution for me.
But a question....
With this solution, there are no optional parameters possible, as for the Start-Process command (adding credentials, control the style or visibility of the Window, etc...)?
So, if any additional settings needed, exist there another solution?

regards

0 Votes 0 ·

If you require more flexibility then Start-Process is the place to look. However, the reason it failed your attempt to use it in your original example is that the "-ArgumentList" parameter accepts an array of argument. Your example gave three separate strings, If you'd separated those strings with commas instead of spaces you'd have had more success. :-)

When you have many parameters to pass using an array of strings in the cmdlet it can make your code difficult to read. A better technique is to build the argument set separately and then use the array variable in the cmdlet.

 $ArgList =  "\\SRV2013-01.db.net\DBs\Database.mdb",
             "/wrkgrp",
             "\\SRV2013-01.db.net\DBs\WGs\MyWorkgroup.mdw"
                
 Start-Process -FilePath "C:\Program Files\Microsoft Office\root\Office16\MSACCESS.EXE" -ArgumentList $ArgList



2 Votes 2 ·
BijuPhilipJacob-4158 avatar image
0 Votes"
BijuPhilipJacob-4158 answered BijuPhilipJacob-4158 published

Thanks Rich

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.