Execution Flow
Synopsis
Uses [System.DirectoryServices.DirectorySearcher] (ADSI) to locate computer objects under a named OU. No ActiveDirectory PowerShell module is required — works on any domain-joined machine. The returned objects have a SqlInstance property equal to the computer FQDN, which allows direct piping to any sqmSQLTool function that accepts -SqlInstance from the pipeline.
No dbatools required. No ActiveDirectory module required — pure .NET ADSI. Uses PageSize=1000 for LDAP paging. With
-Recurse (default), searches sub-OUs as well. Returns objects immediately via Write-Output (streaming pipeline-compatible).Syntax
Get-sqmServersFromOU [-OUName <String>] # default 'srvDatabase' [-Domain <String>] # default: current AD domain [-SearchBase <String>] # explicit LDAP DN; overrides OUName lookup [-Recurse <Bool>] # default $true
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| -OUName | String | srvDatabase | OU name to locate via DirectorySearcher. Ignored when -SearchBase is specified. |
| -Domain | String | current AD domain | AD domain name. Auto-detected from the machine's domain membership. |
| -SearchBase | String | — | Explicit LDAP DN to use as search root, e.g. OU=srvDatabase,DC=corp,DC=contoso,DC=com. |
| -Recurse | Bool | $true | Search all sub-OUs (Subtree) or only direct children (OneLevel). |
Return Value
| Property | Description |
|---|---|
| Name | NetBIOS computer name (AD name attribute). |
| FQDN | Fully qualified DNS name (dnshostname). |
| SqlInstance | Alias of FQDN — enables direct piping to sqmSQLTool functions. |
| OU | Parent OU name extracted from distinguishedname. |
| Domain | AD domain name. |
| OperatingSystem | OS name from AD computer object. |
| Description | Computer description from AD. |
Examples
# List all computers in the default 'srvDatabase' OU Get-sqmServersFromOU # Custom OU name, different domain Get-sqmServersFromOU -OUName "SQL_Servers" -Domain "eu.contoso.com" # Pipeline to disk space report across all SQL servers in OU Get-sqmServersFromOU | Get-sqmDiskSpaceReport -ContinueOnError # Explicit DN for a deep OU Get-sqmServersFromOU -SearchBase "OU=Prod,OU=SQL,DC=corp,DC=contoso,DC=com"