Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

DirectoryEntry ServicePrincipalName SetInfo Contrstraint Violation

$
0
0

Recently I've had to do some work with SPN's and realized that I had no cmdlets for that. So yesterday I wrote a module that wraps setspn.exe into some nice little functions which will work for what I need. But as I thought about it, I would like to be able to do this strictly through .net and since serviceprincipalname is a property in AD I ought to be able to do that.

There are several examples I've found on the internet and this is the one I've settled for.

$User = [adsi]"LDAP://cn=server-01,dc=company,dc=com"

$MultiValProp = @()

$MultiValProp += "MyNewSPN"

$User.PutEx(3,"serviceprincipalname",$MultiValProp)

$User.SetInfo

MemberType          : Method
OverloadDefinitions :
TypeNameOfValue     : System.Management.Automation.PSMethod
Value               :
Name                : setinfo
IsInstance          : True

If I try

$User.SetInfo()

Exception calling "setinfo" with "0" argument(s): "A constraint violation occurred.
"
At line:1 char:14
+ $User.setinfo <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI

I've also tried using DirectoryEntry classes and so forth like this

 

$filter = "(servicePrincipalName=foo/cm12-test)"
$domain = New-Object System.DirectoryServices.DirectoryEntry
$searcher = New-Object System.DirectoryServices.DirectorySearcher
$searcher.SearchRoot = $domain
$searcher.PageSize = 1000
$searcher.Filter = $filter
$results = $searcher.FindAll()

foreach ($result in $results)
{
    $User = $result.GetDirectoryEntry()
    }

The results are roughly the same except when doing

$User.SetInfo

OverloadDefinitions
-------------------

Is all I get. Using parens gives me the constraint violation. I feel as though I'm just doing something stupid, so if someone could point it out to me, i'd really appreciate it! I know often I get caught up on case, in this instance I've cased serviceprincipalname and servicePrincipalName and get the same results.

Thanks,

 

Jeffrey S. Patton Jeffrey S. Patton Systems Specialist, Enterprise Systems University of Kansas 1001 Sunnyside Ave. Lawrence, KS. 66045 (785) 864-0242 | http://patton-tech.com


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>