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

SQL Script to list all DBs Sizes in MBs

SQL Script to list all DBs Sizes in MBs [code language=”sql”] SELECT DbName ,DbState ,DbRecovery ,[ROWS], [LOG], [FILESTREAM], [FULLTEXT] FROM ( SELECT DB.name AS DbName ,DB.state_desc AS DbState ,DB.recovery_model_desc AS DBRecovery ,MF.type_desc AS FileType ,CONVERT(int, ROUND(MF.size * 0.0078125, 0)) AS SizeMB FROM sys.databases AS DB INNER JOIN sys.master_files AS MF ON DB.database_id = MF.database_id WHERE HAS_DBACCESS(DB.name) = 1 ) AS DBS PIVOT (SUM(SizeMB) FOR FileType IN ([ROWS], [LOG], [FILESTREAM], [FULLTEXT]) ) AS PVT ORDER BY DbName [/code]

Read more