$MTauthenticationType = [System.DirectoryServices.AuthenticationTypes]::ServerBind
$MTobjSearcherRoot = New-Object System.DirectoryServices.DirectoryEntry("LDAP://ldap1.micron.com:389/ou=mtgroups,o=********", "uid=*******,ou=mtworkers,o=********", "********" , $MTauthenticationType)
$MTobjSearcher = New-Object System.DirectoryServices.DirectorySearcher($MTobjSearcherRoot)
$MTobjSearcher.ClientTimeout = New-Object System.TimeSpan(0, 0, 61, 0, 0);
$MTobjSearcher.Filter = "cn=KTGROUP4"
$MTresult = $MTobjSearcher.FindAll().Properties
$RemovedUser= $MTresult.Remove('NSIROHI')
// list of the owner looking like
PS C:\WINDOWS\system32> C:\Users\nsirohi\Desktop\Untitled1.ps1
Name Value
---- -----
mailaliased {0}
contactusername {uid=NSIROHI, ou=mtworkers, o=micron.com}
lastreviewdate {20211029}
adspath {LDAP://ldap1.micron.com:389/cn=KTGROUP4,ou=mtgroups,o=*****}
objectclass {top, groupofuniquenames, micron}
lastreviewby {1308732}
cn {KTGROUP4}
companynumber {1000}
reviewdate {20221029}
owner {uid=NSIROHI, ou=mtworkers, o=micron.com, uid=NIKHILJAIN, ou=mtworkers, o=***** uid=ROOHINAS, ou=mtworkers, o=********}
When posting code in the forum, please can you use the preformatted text </> button. It really helps us with readability, and copying and pasting your code (we don’t have to faff about replacing curly quote marks to get things working).
How to format code on PowerShell.org
Are you having a problem with your code? Please let us know how we can help.
1 Like
Hi All,
I tried with someway
$b =$a.owner| ?{$_ -like 'uid=NSIROHI*'}
In $b I'm getting output
uid=NSIROHI, ou=mtworkers, o=micron.com
Now I want to remove UID= NSIROHI from here.
$b.Remove()
It's throwing an error like
Cannot find an overload for "Remove" and the argument count: "0".
At line:1 char:1
+ $b.Remove()
+ ~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest