Discovering Windows Computers


Much like the Operations Manager UI Console the Command Shell offers several ways to discover Windows computers. You can either search by computer name or search by LDAP query. Let start by looking at the diferences between each approach.


The following command defines a LDAP query and passes it to the New-WindowsDiscoveryConfiguration Cmdlet thereby creating an LDAP based WindowsDiscoveryConfiguration.

$query = New-LdapQueryDiscoveryCriteria –LdapQuery: “(sAMAccountType=805306369)(*)” –Domain:””

$discoConfig = New-WindowsDiscoveryConfiguration –LdapQueryDiscoveryCriteria:$query

In contrast the following command defines a name based WindowsDiscoveryConfiguration that will direct discovery to find both and

$discoConfig = New-WindowsDiscoveryConfiguration  -ComputerName: "", ""

There is a lot more you can specify when defining a WindowsDiscoveryConfiguration. The following commands will direct the discovery module to use specific credentials, perform verification of each discovered Windows computer and constrain the type of discovered object to a Windows server. The ComputerType parameter is an enum that can be one of Workstation, Server, or Both. The PerformVerification switch is used to direct the discovery module to verify that only available computers should be returned.

# Prompt for credentials used to perform the discovery.

$creds = Get-Credential

# Define a WindowsDiscoveryConfiguration

$discoConfig = New-WindowsDiscoveryConfiguration –ComputerName: "", "" –PerformVerification: $true –ActionAccount:$creds -ComputerType: "Server"

# Select the Management Server used to run the discovery.

$managementServer = Get-ManagementServer –Root: $true

# Start the discovery process.

$discoResult = Start-Discovery –ManagementServer: $managementServer –WindowsDiscoveryConfiguration: $discoConfig

# Check that the discovery process discovered the Windows computers you specified.


# Last but not least install agents on the discovered computers.

Install-Agent –ManagementServer: $managementServer –AgentManagedComputer: $discoResult.CustomMonitoringObjects

Hope that helps and as always please post your questions and comments and I will make sure they are addressed in future posts.

Roger Sprague

Comments (4)

  1. paulc13 says:

    I’ve tried your code sample on multiple machines running RC2 (one the primary management server and the other a machine running the OM 2007 console). The machine I tried to discover was my primary management server (figured it should have been easy) and in both cases the results were:

    $managementServer was valid

    $discoConfig appeared valid

    $discoResult appeared valid

    $discoResult.MonitoringTaskResults appeared valid

    $discoResult.CustomMonitoringObjects was always empty

    $discoResult.BatchId was always empty

    What was strange was that:



    showed what looked like valid data, even displaying what looked like a valid BatchId as part of their output.

    However outputing $discoResult.BatchId by itself was always empty (which was definitely confusing as outputing $discoResult showed a non empty BatchId field).

    Any ideas why this would return these types of results and not return a valid $discoResult.CustomMonitoringObjects?

  2. scshell says:

    The PowerShell does not properly format instances of type System.Guid. As a work around you must format the string yourself.

    The solution…


    I brought the issue to the attention of the PowerShell team.

    Please not that if the .CustomMonitoringObjects property is empty it is possible that the management server can not see the computer you are attempting to discover. Make sure you can ping the computer from the management server.

  3. sup3rwall says:

    Is there a way to specify discovery to run on a management server other than the RMS?  Thanks!

  4. smurillo100 says:

    As far as I understand from this code the credentials that you catch are for discovery purposes only. I’ve tried to instantiate an InstallAgentConfiguration with no luck to see if it would provide a way to specify an account for installing the agent. It must be possible since the UI console does it.

    Any ideas?

Skip to main content