Solved

Using Powershell to add/update records in an Microsoft Access db

Posted on 2008-10-15
7
1,978 Views
Last Modified: 2011-10-03
Powershell newbie here.

I have a simple powershell script that collects the hardware inventory of a machine, including the serial number.  I'd like to add some code to my script that puts the results in a single MS Access database, so that there is only one db record maintained per serial number.

Thanks!
0
Comment
Question by:DetersLaw
  • 4
  • 2
7 Comments
 
LVL 18

Accepted Solution

by:
BSonPosh earned 250 total points
ID: 22727927
Here is a link that explains exactly what your looking for
http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan08/hey0115.mspx

There is another article written by a Powershell Dev that directed at SQL, but works for Access as well
http://www.leeholmes.com/blog/InteractingWithSQLDatabasesInPowerShellInvokeSqlCommand.aspx

0
 

Author Comment

by:DetersLaw
ID: 22730774
Thanks Bson!

I'll get back with you latr today after some testing.
0
 

Author Comment

by:DetersLaw
ID: 22730999
The script at TechNet is very close.
http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan08/hey0115.mspx

But each time that script is run, it adds a new record.  I'd like something that checks for the existence of the serial number and then updates that record if it exists.  If the serial number does not exist in the db, then add a new record.  IOW, I don't want multiple records for the same serial number.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 18

Expert Comment

by:BSonPosh
ID: 22731423
I think you could add that logic.
0
 

Author Closing Comment

by:DetersLaw
ID: 31506504
Thanks
0
 

Expert Comment

by:metroexpert
ID: 22908282
Was this solved because I need to update a SQL 2000 record base on a name but i dont want to add a new record. Can someone give me the update code. thanks
0
 

Author Comment

by:DetersLaw
ID: 22923559
We set a field in our Access 2k3 database to be indexed, allowing no duplicates.  Our Powershell script needed a line of code (below) so users wouldn't see the ugly errors when it tries to add a new record.  A powershell update code would be perfect, but this works well for us.

$erroractionpreference = "silentlycontinue"
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now