Solved

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

Posted on 2008-10-15
7
2,119 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

713 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