PowerShell Script: Get SCCM Management Point server name from AD

less than 1 minute read

I wrote this function as a part of a script that I’m working on. it searches AD for the management point server name for a particular SCCM site:

Function Get-MPFromAD ($SiteCode)
{
  $domains = Get-AllDomains
  Foreach ($domain in $domains)
  {
    Try {
      $ADSysMgmtContainer = [ADSI]("LDAP://CN=System Management,CN=System," + "$($Domain.Properties.ncname[0])")
      $AdSearcher = [adsisearcher]"(&(Name=SMS-MP-$SiteCode-*)(objectClass=mSSMSManagementPoint))"
      $AdSearcher.SearchRoot = $ADSysMgmtContainer
      $ADManagementPoint = $AdSearcher.FindONE()
      $MP = $ADManagementPoint.Properties.mssmsmpname[0]
    } Catch {}
  }

  Return $MP
}

Note: This function uses another function called Get-AllDomains, which I’ve blogged before here: https://blog.tyang.org/2011/08/05/powershell-function-get-alldomains-in-a-forest/ So make sure you include BOTH functions in your script.

Leave a comment