I'm trying to use the SMO WMI API/objects in PowerShell 2.0 on Windows 7 with SQL Server 2008 R2 installed to get a list of SQL Server instances on the local computer using the Managed Comuter object. However, I'm getting exceptions after I instantiate the objects when I try to access any data on them. I'm running PowerShell as an administrator.

$computer = New-Object Microsoft.SqlServer.Management.Smo.WMI.ManagedComputer ($env:computername)

Results in this error:

The following exception was thrown when trying to enumerate the collection: "An exception occurred in SMO while trying to manage a service.".
At line:1 char:89
+ (New-Object Microsoft.SqlServer.Management.Smo.WMI.ManagedComputer ($env:computername)). <<<< ServerInstances
+ CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException
+ FullyQualifiedErrorId : ExceptionInGetEnumerator

Is there some service I have to enable to get this to work? The WMI service is running. Is there some other setting I need? Why can't I enumerate SQL Server instances?

  • Do you load the Assembly for SQL WMI Management? [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SQLWMIManagement') ?
    – user47078
    Commented Jun 12, 2015 at 3:35
  • I can also note that running that command on my Windows 8.1 machine with two named instances running, shows the ServerInstances is empty.
    – user47078
    Commented Jun 12, 2015 at 3:35

1 Answer 1


Are you running this code as administrator? Access to WMI requires WMI privileges. However, there is an alternate method I use. I documented that here: http://www.powershellmagazine.com/2013/04/24/pstip-enumerate-all-sql-server-instances-in-a-network/

  • I've updated my question to note that I am running as an administrator. Commented Jun 5, 2013 at 19:40
  • That's the workaround I tried. Unfortunately, my script also does some other work with SMO.WMI, and I'm getting similar problems. I really need to get the WMI stuff working. Commented Jun 5, 2013 at 19:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .