Quantcast
Channel: Directory Services forum
Viewing all articles
Browse latest Browse all 31638

powershell error "A constraint violation occurred" on setinfo

$
0
0

I am trying to update the managedBy attribute of a list of groups read from excel. Below is my script which worked fine a month ago but not am getting an error "Exception calling "Setinfo" with "0" argument(s): "A constraint violation occurred.
"
At Update_group managedby.ps1:38 char:26
+         $objgroup.Setinfo <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI

Script:

$Datafile = New-Object -Com Excel.Application
$Datafile.visible = $True
[threading.thread]::CurrentThread.CurrentCulture = 'en-US'
$Excel = $Datafile.Workbooks.open("C:\GroupsOwner.xlsx")
$Sheet = $Excel.Worksheets.Item(1)
$intRow = 2
$null = ""
$Class = "group"
$OwnerName = 'Richard Brown 000031984'
Do {

    $GroupName = $Sheet.Cells.Item($intRow,1).Value()
    $objDomain = New-Object System.DirectoryServices.DirectoryEntry
    $Search = New-Object DirectoryServices.DirectorySearcher([ADSI]"LDAP://DC=abc,DC=xyz,DC=com")
    $Search.filter = "(&(objectCategory=group)(sAMAccountname=$GroupName))"
    $Search.SearchRoot = $objDomain
    $Search.SearchScope = "Subtree"
    $Search.PageSize = 1000
    $group = $Search.FindOne()
    if ($group -ne $null ){
        $dn = $group.properties.item('distinguishedname')
        $objgroup = [ADSI]"LDAP://$dn"
        $objgroup.Put("managedBy","$OwnerName")
        $objgroup.Setinfo()
        }
    $intRow = $intRow + 1

While ($Sheet.Cells.Item($intRow,1).Value() -ne $null) 
$Datafile.quit()

Note: I am running this script using a Domain Admin account. Also, I have tried another method i.e. $objgroup.managedBy = $OwnerName $objgroup.commitchanges() but both ways it throws same error.

Could you please help me on this?


Viewing all articles
Browse latest Browse all 31638

Trending Articles



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