Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9070813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:46:48+00:00 2026-06-16T17:46:48+00:00

I can find sample VBA, and C# code to do this, but no Powershell

  • 0

I can find sample VBA, and C# code to do this, but no Powershell snippets (google is surprisingly silent on this, as is Stackoverflow). Can anyone point me at some Powershell (or provide some) that does this? I’m expecting it would get at Access’s API via COM.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:46:49+00:00Added an answer on June 16, 2026 at 5:46 pm

    I should know better than to ask on the day before Christmas and hope for a quick response, so I did it myself. Turns out the answer is super-simple in any case. The top function below does what I needed and the driver function will loop over all the access databases in a directory and compact each one of them.

    function compactDatabaseFile($sourceFilename, $destinationFileName)
    {
    
        $application =  New-Object -ComObject Access.Application
    
        Write-Host $($(Get-Date).ToString() + ": Starting compacting of $sourceFilename to $destinationFileName")
    
        $application.CompactRepair($sourceFilename,$destinationFileName, $true)
    
        Write-Host $($(Get-Date).ToString() + ": Finished compacting of $sourceFilename to $destinationFileName")
    
        $application.Quit()
    }
    
    function driver($sourceDirectory, $newDestinationDirectory, $filePatterns = @("*.mdb","*.accdb"))
    {
        if (Test-Path $newDestinationDirectory) {
            Write-Host "Destination Directory $newDestinationDirectory exists.  Exiting without doing anything."
            Exit
        }
    
        if (!$(Test-Path $sourceDirectory)) {
            Write-Host "SourceDirectory $sourceDirectory not found.  Exiting without doing anything."
            Exit
        }
    
        mkdir $newDestinationDirectory | Out-Null
    
        gci -path $($sourceDirectory + "\*") -include $filePatterns | % {
            $sourceFileName = $($sourceDirectory + "\" + $_.Name);
            $destinationFileName = $($newDestinationDirectory + "\" + $_.Name);
            compactDatabaseFile $sourceFileName $destinationFilename
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've done this before, but can't find the sample code...still new to c++. I
I have searched but can't find why this simple code will fail in Drools
Does anyone knows where I can find tutorials and code samples, basic and advanced,
This is probably quite simple but I've googled and can't find an answer. I
can anybody tell me where can i find some tutorials/ sample code on how
I have tried every sample of code I can find that defines and runs
I'm very new to VBA and i searched and searched on Google, but can't
I am wondering if anyone can find a sample or has a sample or
GitHub uses D3 library for its graphs but I can't find any sample similar
is there any links where we can find sample source code/ tutorial / help

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.