$CountryGroup = New-Object System.DirectoryServices.DirectoryEntry( $LDAP +
"OU=USERS,OU=_DE,DC=me-dus,DC=de" )
# Create a selector and start searching from the Root of AD
$searcher = New-Object
System.DirectoryServices.DirectorySearcher($CountryGroup)
$searcher.Filter = "(&(objectCategory=person)(objectClass=user))"
$searcher.PropertiesToLoad.Add("distinguishedName") >$null
$searcher.PropertiesToLoad.Add("sAMAccountName") >$null
$searcher.PropertiesToLoad.Add("givenname") >$null
$searcher.PropertiesToLoad.Add("sn") >$null
$result = $searcher.FindAll()
"There are $($result.count) objects in the $($CountryGroup.name) domain"
foreach ($person in $result)
{
$prop = $person.Properties
Write-Host $($prop["givenname"])
Write-Host $($prop["sAMAccountName"])
#Write-Host "First Name: $($prop.givenname) Surname: $($prop.sn)
sAMAccountName: $($prop[""[sAMAccountName""])"
if(!(Test-Path ("C:\0\" + $prop.cn)))
{
Write-Host "Directory not found... ($($prop[""[sAMAccountName""]))"
}
}
This script print out "givenName" but not "sAMAccoutName.
I'am new to PowerShell and found this link in Web:
I don't see any diffrences :-(((
Try this...
##################
$CountryGroup = New-Object System.DirectoryServices.DirectoryEntry(
"LDAP://OU=USERS,OU=_DE,DC=me-dus,DC=de" )
$filter = "(&(objectCategory=user))"
$props = "sAMAccountName","givenname","sn"
$searcher = New-Object
System.DirectoryServices.DirectorySearcher($CountryGroup,$filter,$props)
$result = $searcher.FindAll()
foreach ($person in $result)
{
$prop = $person.Properties
Write-Host $person.properties.givenname
Write-Host $person.properties.samaccountname
#Write-Host "First Name: $($prop.givenname) Surname: $($prop.sn)
sAMAccountName: $($prop[""[sAMAccountName""])"
if(!(Test-Path ("C:\0\" + $prop.cn)))
{
Write-Host "Directory not found... ($($prop[""[sAMAccountName""]))"
}
}
"Daniel Schmitz" <d...@me-dus.de> wrote in message
news:48ABC521-B441-4882...@microsoft.com...
Point 1) is the solution, that i searched for many hours.
But one question. I write the same code in C# and in C# it works fine with
non lowercase properties!? Why??
"Daniel Schmitz" <d...@me-dus.de> wrote in message
news:694F750E-D87E-41AA...@microsoft.com...
"Please note that the ADSI query is case-sensitive, so name and description
must be written in lower-case letters."
English download (16 MB):
http://blogs.technet.com/chitpro-de/archive/2008/02/28/free-windows-powershell-workbook-server-administration.aspx
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
There is a bug in Powershell that marks the Collection returned from
DirectorySearcher to be case-sensitive (and it doesnt even do it right. IF
ANYTHING it should be camelcase.)
The Bug is filed on connect.
The work around is to use the item() method on the properties collection.
Like: $user.properties.item('sAMAccountName')
"Shay Levi" <n...@addre.ss> wrote in message
news:8766a944217c08...@news.microsoft.com...
Well, this is for Frank to answer. One can conclude that the 'ADSI query
is case-sensitive' not the ADSI type.
What bothers me is even if it is 'case-sensitive', 'sAMAccountName' is not
the same as 'SAMAccountName', so the first should work.
Does 'case-sensitive' means 'lower-case-sensitive'? So many questions :)
btw... it is the same for V2 so I am using item() and suggest that all do
the same. Also... go vote for my bug on connect :)
https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=329952&SiteID=99
"Shay Levi" <n...@addre.ss> wrote in message
news:8766a94421c768...@news.microsoft.com...
I just did.
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
> It is actually quite the opposite. ADSI query is NOT case-sensitive.
>>>> -p owershell-workbook-server-administration.aspx