LDAP query error: the following exception occurred while retrieving member "distinguishedname": "unknown error (0x80005000)"


hi guys,

i'm using sccm osd taks run powershell script set computer name, problem getting list of pc names taken on domain giving me error: "the following exception occurred while retrieving member "distinguishedname": "unknown error (0x80005000)"", line:

$root = new-object system.directoryservices.directoryentry($ldapconn,"username","pass")  -erroraction stop

if run script on computer work, if machine not joined domain , firewall turned on. reason of error?

here full script:

$destdir = "c:\temp"   if (!(test-path $destdir)) { new-item -path $destdir -itemtype directory -force |out-null}  new-item c:\temp\log.txt -type file -force | out-null  #create array contains domain controllers  $dcips = @("10.10.10.10","10.10.10.10","10.10.10.10","10.10.10.10")  #create variable first element of array  $dc = $dcips[0]  #create variable used onthe "while" loop  $i = 0  #test if domain controller have connection, if not search available array  if ((test-connection $dc -quiet) -eq $false){while ( (test-connection $dcips[$i] -quiet)-eq $false ){ $i++;$dc = $dcips[$i]}}  "- domain controller ip"|out-file c:\temp\log.txt -append  $dc|out-file c:\temp\log.txt -append  "- check connectivity dc"|out-file c:\temp\log.txt -append  test-connection $dc -quiet|out-file c:\temp\log.txt -append  #create connection string  $ldapconn = "ldap://$dc/dc=subdomain,dc=domain,dc=com"  "- review ldap string"|out-file c:\temp\log.txt -append  $ldapconn|out-file c:\temp\log.txt -append  #create instance of directoryentry class , set connection values  try{  $root = new-object system.directoryservices.directoryentry($ldapconn,"username","pass")  -erroraction stop  "- root variable"|out-file c:\temp\log.txt -append  $root|out-file c:\temp\log.txt -append  }  catch{   $errormessage = $_.exception.message|out-file c:\temp\log.txt -append   $faileditem = $_.exception.itemname|out-file c:\temp\log.txt -append  }    #create instance of directorysearcher class  $searcher = new-object system.directoryservices.directorysearcher($root)  #set filter property yo searcher instance, on case search computer objects name pc*cr  $searcher.filter = "(&(objectclass=computer)(name=pc*cr))"  #set pagesize property, amount of objetcs returned searcher  $searcher.pagesize = 10000  "- searcher variable"|out-file c:\temp\log.txt -append  $searcher|out-file c:\temp\log.txt -append  #create instance of resultcollection class , run search of objects in ad  [system.directoryservices.searchresultcollection]$results = $searcher.findall()  "- total results received"|out-file c:\temp\log.txt -append  $results.count|out-file c:\temp\log.txt -append  #pass pc names new variable  foreach ($result in $results){$pcnames += $result.properties.name}  #create regular expression contains letters  $pattern = '[a-za-z]'  #remove letters results in order keep numbers , make sort  $n = ($pcnames) -replace $pattern, ''|sort-object @{e={$_ -as [int]}}  #create variable used while loop  $y = 1  #while loop search next available number results  while ($n -contains $y){$y++}  #create new machine nambe based on while's result  $osdcomputername = "pc"+ $y + "cr"  "- name assigned"|out-file c:\temp\log.txt -append  $osdcomputername|out-file c:\temp\log.txt -append  #create variable of type "task sequence"  $tsenv = new-object -comobject microsoft.sms.tsenvironment  #assing new pc name variable   $tsenv.value("osdcomputername") = "$osdcomputername"

did post in sccm forum help.  way sccm session mis built can have issue.  if sccm executing on new machine in violation of second hop restriction.


\_(ツ)_/



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

server manager error: ADAM.events.xml could not be enumerated.

Cannot access Anywhere Access using domain name?

WMI Failure: Unable to update Local Resource Group