PowerShell Script to Update MS Access (.MBD) Database

PowerShell Script to Update MS Access (.MBD) Database [code language=”powershell”] ########################################################################### # # NAME: Update-MSAccessDB-Via-UserDSN # # AUTHOR: Govardhan Gunnala # # COMMENT: # 1. Updates MDB file records via "MS Access Database" User DSN # 2. Creates "MS Access Database" USER DSN if not already exists # 3. Sets the "MS Access Database" USER DSN to custom .MDB file # 4. Process all the data Column by Column # 5. Searches and Replaces a partial string in whole table data # # # VERSION HISTORY: 1.0 7/18/2011 – Initial release # ########################################################################### # Import Registry Keys to create a […]

Read more

PowerShell Script to Query Specified Columns of a .MDB DataBase

Script connects to the .MDB file using user DSN named “MS Access Database” pointing to the .MDB file and then queries the specified columns. [code language=”powershell”] $adOpenStatic = 3 $adLockOptimistic = 3 $userName = $env:USERNAME $newDbPath = "C:\Temp\$userName\DPW" $connectionString = "DSN=MS Access Database;" $sourceQuery = "Select * From Connection" $objConnection = New-Object -com "ADODB.Connection" $objRecordSet = New-Object -com "ADODB.Recordset" $objConnection.Open($connectionString) $objRecordset.Open($sourceQuery, $objConnection, $adOpenStatic, $adLockOptimistic) $objRecordset.MoveFirst() While ($objRecordset.EOF -ne $True) { ForEach ($column in "ConnectString", "FilePath", "BackupPath") { $objRecordset.Fields.Item("$column").Value } $objRecordset.MoveNext() } $objRecordset.Close() $objConnection.Close() [/code] .

Read more

PowerShell Script to Restrict Application to a Single Instance

Here is a simple Powershell code that checks if a specified process is already running and launches second instance of the application if it’s not already running. [code language=”powershell”] $process = "mspaint" $ret = Get-Process -Name $process -ErrorAction SilentlyContinue if ($ret) { Write-Host "INFO: $process already running, skipping start of another instance of the same process" } else { Write-Host "VERBOSE: Starting $process now" Invoke-Item "$process.exe" } [/code] .

Read more