[Python] Accessing SQL Server Configuration Manager with Python

Discussão em 'Python' iniciado por Stack, Fevereiro 24, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using Python with the 'wmi' and 'pyodbc' libraries in order to automate a server inventory of a list of VMs. Per VM, I'm trying to get a list of all MS SQL Server products, the SQL Server database instance name, number of databases, databases on that engine, engine version, etc. and will eventually put it on a excel spreadsheet. For now, I'm simply line printing on the console with information from just one machine.

    I'm able to get most of my information by running a T-SQL query using metadata function SERVERPROPERTY, and then running a cursor and printing the information by line. For example:

    SERVERPROPERTY('MachineName')
    SERVERPROPERTY('ProductVersion')
    SERVERPROPERTY('Edition')


    The only hiccup that I have is gathering all of the installed SQL Server Services that are displayed in SQL Server Configuration Manager, specifically the SQL Server Services tab as shown below: SQL Server Configuration Manager

    Is there another library, or pyodbc, that is able to access SQL Server Configuration Manager in order for me to get this list of services?

    As a side note, I used wmi's win32_Product class to try to retrieve anything related to SQL Server, but it returns too much much unwanted returns, like language packs, drivers, etc.

    server_connection = wmi.WMI(server, user=username, password=password)
    task = server_connection.Win32_Product()
    `for service in task:`
    `if 'SQL Server' in service.Caption:`
    `print(f"Service Name: {service.Caption}")`

    Continue reading...

Compartilhe esta Página