Friday, 15 May 2015

Escaping spaces in powershell LDAP path -



Escaping spaces in powershell LDAP path -

i have next powershell code:

$strcategory = "computer" $objdomain = new-object system.directoryservices.directoryentry("ldap://ou=computers,ou=2 streetsville,dc=ourdomain,dc=local") $objsearcher = new-object system.directoryservices.directorysearcher($objdomain) $objsearcher.filter = ("(objectcategory=$strcategory)") $colproplist = "name" foreach ($i in $colproplist){[void]$objsearcher.propertiestoload.add($i)} $colresults = $objsearcher.findall()

the code worked fine when our ldap path contained no spaces:

ldap://ou=computers,ou=datacenter,dc=ourdomain,dc=local

however when renamed our datacenter ou address:

ldap://ou=computers,ou=2 streetsville,dc=ourdomain,dc=local

suddenly code no longer works.

i figured no problem need escape space \:

ldap://ou=computers,ou=2\ streetsville,dc=ourdomain,dc=local

however doesn't work. tried double slash escape space:

ldap://ou=computers,ou=2\\ streetsville,dc=ourdomain,dc=local

i'm @ loss else try. go spaceless ou name i'd rather not. can help me figure out how escape space?

try:

.... directoryentry('ldap://ou=computers,ou="2 streetsville",dc=ourdomain,dc=local')

powershell ldap space

No comments:

Post a Comment