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 7857623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:05:36+00:00 2026-06-02T21:05:36+00:00

I need to get a list of SQL server instances present on a computer,

  • 0

I need to get a list of SQL server instances present on a computer, get a list of databases in each instance, and then determine how much space each database is taking up.

I can easily grab the instance names from the registry, but I don’t have access to query the tables to get the names of the databases. Is there another way of doing this, maybe though WMI?

  • 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-02T21:05:40+00:00Added an answer on June 2, 2026 at 9:05 pm

    After some digging around, I finally found the WMI Class that will get my the info I need. On a server where I have 3 instances of SQL Server, I found my data in the following classes

    Win32_PerfFormattedData_MSSQLINST2_MSSQLINST2Databases
    Win32_PerfFormattedData_MSSQLINST3_MSSQLINST3Databases
    Win32_PerfFormattedData_MSSQLSERVER_SQLServerDatabases
    

    My instances are MSSQLINST2, MSSQLINST3 and MSSQLSERVER. I couldn’t figure out the naming scheme, so I had to look though all the classes to find out the information I needed. Anyway, here’s the code that’s working. Maybe someone will find it useful.

    ManagementObjectSearcher sqlInstancesSearcher = new ManagementObjectSearcher(
        new ManagementScope(@"Root\Microsoft\SqlServer\ComputerManagement10"),
        new WqlObjectQuery("select * from SqlServiceAdvancedProperty where propertyindex = 12"),
        null);
    
    foreach (ManagementObject instance in sqlInstancesSearcher.Get())
    {
        string instanceName = instance["ServiceName"].ToString().Replace("$", String.Empty);
        Console.WriteLine("INSTANCE: " + instanceName);
    
        ManagementObjectSearcher classNameSearcher = new ManagementObjectSearcher(
            new ManagementScope(@"root\cimv2"),
            new WqlObjectQuery("select * from meta_class where __CLASS Like 'Win32_PerfFormattedData_" + instanceName + "%Databases%'"),
            null);
    
        foreach (ManagementClass wmiClass in classNameSearcher.Get())
        {
            string className = wmiClass["__CLASS"].ToString();
            string query = "select * from " + className;
    
            ManagementObjectSearcher databaseSearcher = new ManagementObjectSearcher(
                new ManagementScope(@"root\cimv2"),
                new WqlObjectQuery(query),
                null);
    
            foreach (ManagementObject database in databaseSearcher.Get())
            {
                Console.WriteLine("  " + database["Name"]);
                Console.WriteLine("    Data Files     : " + database["DataFilesSizeKB"]);
                Console.WriteLine("    Log Files      : " + database["LogFilesSizeKB"]);
                Console.WriteLine("    Log Files Used : " + database["LogFilesSizeKB"]);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a query on SQL server to get the list of
I need a query for SQL Server 2000 to get a list of all
i have a problem with sql query. I need to get list of users.
I need to list all triggers in SQL Server database with table name and
Using SQL Server 2000 I want to get the max(date) of total for each
I need to get a list of all tables that are published for replication
I need to get a list of tags in a text, make their contents
i need to get the list of domain names on my network... but i
I need to get the list of dates between two dates - for e.g.
I have a little doubt. I need to get a list of the files

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.