Request / change SPN in a Windows domain without SetSPN

Is anyone lucky with requesting / modifying an SPN in a Windows domain? Most of the hits on Google are related to SQL: I cannot find any information on how to do this myself. The most important would be SPN configuration queries and duplicate checking.

According to Arnout, I made the following code:

static void Main(string[] args) {
    ValidateSPN("K2Server/jonathand-vpc:5252");
}

static void ValidateSPN(string spn) {
    const string queryFormat = "(ServicePrincipalName={0})";
    using (Domain localDomain = Domain.GetCurrentDomain()) {
        using (DirectorySearcher search = new DirectorySearcher(localDomain.GetDirectoryEntry())) {
            search.Filter = string.Format(queryFormat, spn);
            search.SearchScope = SearchScope.Subtree;
            SearchResultCollection collection = search.FindAll();
            if (collection.Count > 1)
                throw new Exception("Duplicate SPNs found.");
            else if (collection.Count == 0)
                throw new Exception("No such SPN");
        }
    }
}
+3
source share
2 answers

It looks like this information is stored in the servicePrincipalNameAD attribute . See this page for more details , in particular the "LDIFDE Search" section.

+2
source

You can use Search.VBS in support tools to find duplicate SPNs:

"C:\Program Files\Support Tools\search.vbs" "LDAP://DC=Your,dc=Domain,dc=Here" /C:"(serviceprincipalname=K2Server/jonathand-vpc:5252)" /S:Subtree /P:DistinguishedName
0

All Articles