Tuesday, May 13, 2014

Leveling an LDAP Query String

The neat freak in me likes to level strings in code to make them easier to read.  This is just a little trick to level a string containing an LDAP filter before sending it to Get-ADUser.

The trick is to just level the string out, but remove the CR and LF using the –replace operator.

The LDAPFilter variable will then contain something usable by Get-ADUser while you still get to look at something easy to read.


$LDAPFilter = "






)" -replace "`r" -replace "`n"


Get-ADUser -LDAPFilter $LDAPFilter


No comments: