Thor Logo dbatools

Get-DbaManagementObject

View Source
Ben Miller (@DBAduck), dbaduck.com
Windows, Linux, macOS

Synopsis

Discovers installed SQL Server Management Object (SMO) assemblies and their load status

Description

Scans the system for SQL Server Management Object (SMO) assemblies, SqlClient libraries, and SNI modules to help troubleshoot version conflicts and connectivity issues. This function checks both the Global Assembly Cache (GAC) and currently loaded assemblies in the PowerShell session, returning version information, load status, file paths, and ready-to-use Add-Type commands. Particularly useful when diagnosing why different SQL Server tools behave differently or when you need to load specific SMO versions in PowerShell scripts.

Syntax

Get-DbaManagementObject
    [[-ComputerName] <DbaInstanceParameter[]>]
    [[-Credential] <PSCredential>]
    [[-VersionNumber] <Int32>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Get-DbaManagementObject

Returns all versions of SMO on the computer

Example: 2
PS C:\> Get-DbaManagementObject -VersionNumber 13

Returns just the version specified. If the version does not exist then it will return nothing.

Optional Parameters

-ComputerName

Specifies the Windows server(s) where you want to scan for SMO assemblies and SQL Client libraries.
Use this when troubleshooting SMO version conflicts across multiple servers or when checking which SQL Server tools are installed on remote machines.

PropertyValue
Alias
RequiredFalse
Pipelinetrue (ByValue)
Default Value$env:COMPUTERNAME
-Credential

This command uses Windows credentials. This parameter allows you to connect remotely as a different user.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-VersionNumber

Filters results to show only assemblies matching the specified major version number (e.g., 13 for SQL Server 2016, 14 for 2017, 15 for 2019).
Use this when you need to verify if a specific SQL Server version’s SMO libraries are installed, particularly when troubleshooting version compatibility issues between different SQL Server tools.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value0
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with “sea of red” exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this “nice by default” feature off and enables you to catch exceptions with your own try/catch.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse

Outputs

PSCustomObject

Returns information about SQL Server Management Object (SMO) assemblies, SqlClient libraries, and SNI modules found on the system or loaded in the PowerShell session. One object is returned per assembly or module discovered.

Properties:

  • ComputerName: Name of the computer where the assembly or module is located
  • Version: Version number of the assembly or module
  • Loaded: Boolean indicating if the assembly/module is currently loaded in the PowerShell session
  • Path: File path to the assembly or module; null for Global Assembly Cache (GAC) assemblies
  • LoadTemplate: Ready-to-use PowerShell command to load the assembly/module via Add-Type

Multiple output types may be included:

  • Local SMO assemblies from PowerShell installation directories (with file paths)
  • Global Assembly Cache (GAC) assemblies (without file paths, using AssemblyName)
  • Loaded assemblies currently in the AppDomain (with location information)
  • SNI modules with corresponding SqlClient assembly references Use the LoadTemplate property to quickly load discovered assemblies in PowerShell scripts.