$exportPath = "C:\Certs"
  if (!(Test-Path -Path $exportPath)) {
      New-Item -Path $exportPath -ItemType Directory -Force
  }

  $certs = Get-ChildItem -Path Cert:\LocalMachine\CA

  $stores = @(
      "Root",              # Trusted Root Certification Authorities
      "CA",                # Intermediate Certification Authorities
      "My",                # Personal Certificates
      "TrustedPeople",     # Trusted People
      "TrustedPublisher",  # Trusted Publishers
      "AuthRoot",          # Third-party root certificates
      "Trust",             # Enterprise Trust
      "Disallowed"         # Revoked/untrusted certificates
  )

  # Loop through each store and export the certificates
  foreach ($store in $stores) {
      Write-Output "Processing store: $store"
      $certs = Get-ChildItem -Path "Cert:\LocalMachine\$store"
      foreach ($cert in $certs) {
          $certFileName = "$exportPath\$store-$($cert.Thumbprint).cer"

          try {
              Export-Certificate -Cert $cert -FilePath $certFileName -Type CERT
              Write-Output "Exported: $certFileName"
          } catch {
              Write-Output "Failed to export: $($cert.Subject)"
          }
      }
  }

  Write-Output "All certificates exported to: $exportPath"