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");
}
}
}
source
share