<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ravindar Karampuri</title>
    <description>The latest articles on Forem by Ravindar Karampuri (@ravindar_karampuri_73408a).</description>
    <link>https://forem.com/ravindar_karampuri_73408a</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3420637%2F889380ee-2c0c-48a6-8139-d7f189649765.png</url>
      <title>Forem: Ravindar Karampuri</title>
      <link>https://forem.com/ravindar_karampuri_73408a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ravindar_karampuri_73408a"/>
    <language>en</language>
    <item>
      <title>Automating MongoDB Atlas Cluster Discovery Across All Projects Using PowerShell</title>
      <dc:creator>Ravindar Karampuri</dc:creator>
      <pubDate>Thu, 06 Nov 2025 09:33:52 +0000</pubDate>
      <link>https://forem.com/ravindar_karampuri_73408a/automating-mongodb-atlas-cluster-discovery-across-all-projects-using-powershell-36fn</link>
      <guid>https://forem.com/ravindar_karampuri_73408a/automating-mongodb-atlas-cluster-discovery-across-all-projects-using-powershell-36fn</guid>
      <description>&lt;h2&gt;
  
  
  Overview:
&lt;/h2&gt;

&lt;p&gt;When managing multiple MongoDB Atlas projects within an organization, it often becomes challenging to keep track of all clusters - their configurations, regions, versions, and scaling details - across projects.&lt;br&gt;
Instead of manually navigating through the Atlas UI, you can leverage the MongoDB Atlas Admin API and a simple PowerShell automation script to fetch this data programmatically.&lt;br&gt;
In this guide, we'll build a PowerShell script that connects to the MongoDB Atlas Admin API, retrieves all projects in your organization, and exports detailed cluster information into a CSV (or Excel) file - all with a single command.&lt;br&gt;
&lt;strong&gt;💡 Why Use PowerShell for MongoDB Atlas Automation?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;PowerShell provides a flexible scripting environment that works seamlessly with REST APIs.&lt;/li&gt;
&lt;li&gt;When combined with MongoDB Atlas Admin API, it allows administrators and DevOps engineers to:&lt;/li&gt;
&lt;li&gt;Fetch cluster and project data in bulk&lt;/li&gt;
&lt;li&gt;Automate reporting for governance or audits&lt;/li&gt;
&lt;li&gt;Simplify multi-project monitoring&lt;/li&gt;
&lt;li&gt;Integrate Atlas metadata into enterprise dashboards&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;🔑 Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Before running the script, ensure you have:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;MongoDB Atlas Programmatic API Keys&lt;/li&gt;
&lt;li&gt;Log in to MongoDB Atlas → Organization Settings → Access Manager → API Keys&lt;/li&gt;
&lt;li&gt;Note down your Public Key and Private Key&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Organization Access Level:
The API key must have Organization Read Only or Organization Owner role.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Define your MongoDB Atlas API credentials and organization ID
$publicKey = ""
$privateKey = "-79fd-4e02--"
$orgId = ""

# Base64 encode the API keys
#$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$publicKey:$privateKey"))

#Path to the csv &amp;amp; excel file to be saved
$csvFilePathAtlas = "D:\sampleset.csv"
# Delete file if exist
if (Test-Path $csvFilePathAtlas) 
{
  Remove-Item $csvFilePathAtlas
}

# Define array to collect all project cluster data
$exportRecords = @()

# Fetch projects
$projectsUrl = "https://cloud.mongodb.com/api/atlas/v1.0/groups"

#$projectsResponse = Invoke-RestMethod -Uri $projectsUrl -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

[securestring]$secStringPassword = ConvertTo-SecureString $privateKey -AsPlainText -Force

[pscredential]$credential = New-Object System.Management.Automation.PSCredential ($publicKey, $secStringPassword)
$projectsResponse = Invoke-RestMethod -Uri $projectsUrl -Headers @{Authorization = "Basic $base64AuthInfo"} -Credential $credential -Method Get 
$projectsinfo = $projectsResponse.results

# Iterate over each project and fetch cluster details
foreach ($project in $projectsResponse.results) {
    $projectId = $project.id
    $projectName = $project.name

    # Fetch clusters for the project
    $clustersUrl = "https://cloud.mongodb.com/api/atlas/v1.0/groups/$projectId/clusters"
    $clustersResponse = Invoke-RestMethod -Uri $clustersUrl -Headers @{Authorization = "Basic $base64AuthInfo"} -Credential $credential -Method Get

    # Output project and cluster details
    Write-Output "Project ID: $projectId"
    Write-Output "Project Name: $projectName"
    #Write-Output "Clusters:"

  # Collect each cluster's info
  foreach ($cluster in $clustersResponse.results) {

        $record = [PSCustomObject]@{
     ProjectID    = $projectId
        ProjectName    = $projectName
        ClusterName    = $cluster.name
        MongoVersion   = $cluster.mongoDBVersion
        Connectionstr  = $cluster.connectionStrings.standardSrv
        DiskSizeGB     = $cluster.diskSizeGB
        InstanceSize   = $cluster.providerSettings.instanceSizeName
        RegionName     = $cluster.providerSettings.regionName
        ProviderName   = $cluster.providerSettings.providerName
        Backuptype     = $cluster.backupEnabled
        Scaling        = $cluster.autoScaling.diskGBEnabled
        Pointintimes   = $cluster.pitEnabled

        }

                # Add record to master array
        $exportRecords += $record
    }
    }
    $exportRecords | Select-Object ProjectID,ProjectName, ClusterName,MongoVersion, Connectionstr,DiskSizeGB, InstanceSize,RegionName,ProviderName, Backuptype,Scaling,Pointintimes  | Export-Csv -Path $csvFilePathAtlas -NoTypeInformation

    Write-Output "Exported ClusterInfo to file, please check the location!!!"
# Export the data to an Excel file
#$exportRecords | Export-Excel -Path "Project_ClusterInfo.xlsx" -WorksheetName "Cluster Info" -AutoSize
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>mongodb</category>
      <category>tutorial</category>
      <category>automation</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
