PowerShell: ADSI and Case Sensitivity

In developing a custom PowerShell script which leveraged ADSI, I noticed that the script wasn’t working properly.

Here’s a sample block of the script which uses ADSI to get changes made to ExtensionAttribute11 as part of an Active Directory Convergence test script:

1
2
3
4
$ADSITarget = [ADSI]”LDAP://$DC”
$Searcher = New-Object DirectoryServices.DirectorySearcher($ADSITarget,”(sAMAccountName=$ConvergenceObject)”)
$ConvergenceObjectData = ($Searcher.FindOne()).properties
$ConvergenceObjectDataValue = (($Searcher.FindOne()).properties).ExtensionAttribute11

I usually use Title Case when typing attributes and the script block above was not populating the variable “$ConvergenceObjectDataValue” with any data even though the attribute had data. I realized after enumerating the variable $ConvergenceObjectData that the attribute name was displayed as extensionattribute11 not ExtensionAttribute11.  After changing line #1 to line #2, it worked:

Line #1:
$ConvergenceObjectDataValue = (($Searcher.FindOne()).properties).ExtensionAttribute11

Line #2:
$ConvergenceObjectDataValue = (($Searcher.FindOne()).properties).extensionattribute11

So, be careful when using ADSI (or any other API) since it may be case sensitive.

(Visited 785 times, 1 visits today)