PowerShell case sensitivity?


what occasions when writing powershell script have pay strict attention case sensitivity?
i know powershell case insensitive.  for example, get-childitem same get-childitem, , can use case sensitive forms of comparison operators, -ceq example.

this thread prompted me continue research wanted after similar thread brought subject of case sensitivity. in earlier thread:

http://social.technet.microsoft.com/forums/en-us/winserverpowershell/thread/b95eb187-16fe-41d0-bd8e-2f22b1e5f140

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

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file