PowerShell case sensitivity?
this thread prompted me continue research wanted after similar thread brought subject of case sensitivity. in earlier thread:
kazun stated properties in code similar below must specified in lower case:
$filter = "(&(objectcategory=person)(objectclass=user))"
$domain = new-object system.directoryservices.directoryentry
$searcher = new-object system.directoryservices.directorysearcher
$searcher.searchroot = $domain
$searcher.pagesize = 200
$searcher.filter = $filter
$searcher.searchscope = "subtree"
$searcher.propertiestoload.add("userprincipalname") > $null
$searcher.propertiestoload.add("samaccountname") > $null
$results = $searcher.findall()
$results | foreach {
# attribute names here case sensitive. must lower case.
$upn = $_.properties.userprincipalname
$ntname = $_.properties.samaccountname
"$upn,$ntname"
}
-----
i thought knew better, , replied that active directory is case aware, not case sensitive. right in principal, wrong in case (sorry kazun). i tested , above fails unless attribute names lower case. i fooled because when enumerate results way do, attribute names truely case insensitive. example, works fine:
foreach ($result in $results)
{
# attribute names here case insensitive.
$upn = $result.properties.item("userprincipalname")
$ntname = $result.properties.item("samaccountname")
"$upn,$ntname"
}
-----
notice subtle difference. not understand why, if use pipeline in first example, attribute names must in lower case. more strange ad case insensitive, actual attribute names in ad not lower case. actual attribute names in example are: userprincipalname, samaccountname. powershell automatically marshal properties in pipeline in lower case?
richard mueller - mvp directory services
Windows Server > Windows PowerShell
Comments
Post a Comment