![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | AD Search error I have a text file that contain user names users.txt -------------- user1 user2 user3 i use this code to get the user dn #============== $Searcher = New-Object DirectoryServices.DirectorySearcher cat C:\users.txt | % { $Searcher.Filter = "(&(objectCategory=person)(objectClass=user)(samAccountName=$_))" $usr = $Searcher.FindOne().GetDirectoryEntry() $usr.distinguishedname # do aome other stuff based on user dn } #============== The first iteration returns the first user's dn, but the second iteration rerurns an error You cannot call a method on a null-valued expression. At C:\as400.ps1:62 char:46 + $usr = $Searcher.FindOne().GetDirectoryEntry( <<<< ) -- $hay http://scriptolog.blogspot.com |
My System Specs![]() |
| | #2 (permalink) |
| Guest | RE: AD Search error Does it work if you just use the second name as input? can you do a search in AD on that name & find the information? -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "$hay" wrote: > I have a text file that contain user names > > users.txt > -------------- > user1 > user2 > user3 > > i use this code to get the user dn > > #============== > $Searcher = New-Object DirectoryServices.DirectorySearcher > > cat C:\users.txt | % { > $Searcher.Filter = > "(&(objectCategory=person)(objectClass=user)(samAccountName=$_))" > $usr = $Searcher.FindOne().GetDirectoryEntry() > $usr.distinguishedname > > # do aome other stuff based on user dn > } > > #============== > > > The first iteration returns the first user's dn, but > the second iteration rerurns an error > > You cannot call a method on a null-valued expression. > At C:\as400.ps1:62 char:46 > + $usr = $Searcher.FindOne().GetDirectoryEntry( <<<< ) > > > -- > $hay > http://scriptolog.blogspot.com > > > > |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: AD Search error trying manually : $Searcher = New-Object DirectoryServices.DirectorySearcher $Searcher.Filter = "(&(objectCategory=person)(objectClass=user)(samAccountName=user1))" $usr = $Searcher.FindOne().GetDirectoryEntry() $usr.distinguishedname $Searcher.Filter = "(&(objectCategory=person)(objectClass=user)(samAccountName=user2))" $usr = $Searcher.FindOne().GetDirectoryEntry() $usr.distinguishedname output: CN=user1 name,OU=Users,DC=somedomainname You cannot call a method on a null-valued expression. At C:\as400.ps1:62 char:45 + $usr = $Searcher.FindOne().GetDirectoryEntry( <<<< ) CN=user1 name,OU=Users,DC=somedomainname this always returns (in addition to the error) the dn for user1 I checked for users existence and they are OK. -- $hay http://scriptolog.blogspot.com "RichS" <RichS@discussions.microsoft.com> wrote in message news:52EE787C-4A4A-4C12-8E3D-89F20ED82DF9@microsoft.com... > Does it work if you just use the second name as input? > > can you do a search in AD on that name & find the information? > > -- > Richard Siddaway > Please note that all scripts are supplied "as is" and with no warranty > Blog: http://richardsiddaway.spaces.live.com/ > PowerShell User Group: http://www.get-psuguk.org.uk > > > "$hay" wrote: > >> I have a text file that contain user names >> >> users.txt >> -------------- >> user1 >> user2 >> user3 >> >> i use this code to get the user dn >> >> #============== >> $Searcher = New-Object DirectoryServices.DirectorySearcher >> >> cat C:\users.txt | % { >> $Searcher.Filter = >> "(&(objectCategory=person)(objectClass=user)(samAccountName=$_))" >> $usr = $Searcher.FindOne().GetDirectoryEntry() >> $usr.distinguishedname >> >> # do aome other stuff based on user dn >> } >> >> #============== >> >> >> The first iteration returns the first user's dn, but >> the second iteration rerurns an error >> >> You cannot call a method on a null-valued expression. >> At C:\as400.ps1:62 char:46 >> + $usr = $Searcher.FindOne().GetDirectoryEntry( <<<< ) >> >> >> -- >> $hay >> http://scriptolog.blogspot.com >> >> >> >> |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: AD Search error Do you need to recreate $Searcher each time? -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "$hay" wrote: > trying manually : > > $Searcher = New-Object DirectoryServices.DirectorySearcher > > $Searcher.Filter = > "(&(objectCategory=person)(objectClass=user)(samAccountName=user1))" > $usr = $Searcher.FindOne().GetDirectoryEntry() > $usr.distinguishedname > > $Searcher.Filter = > "(&(objectCategory=person)(objectClass=user)(samAccountName=user2))" > $usr = $Searcher.FindOne().GetDirectoryEntry() > $usr.distinguishedname > > output: > > CN=user1 name,OU=Users,DC=somedomainname > You cannot call a method on a null-valued expression. > At C:\as400.ps1:62 char:45 > + $usr = $Searcher.FindOne().GetDirectoryEntry( <<<< ) > CN=user1 name,OU=Users,DC=somedomainname > > this always returns (in addition to the error) the dn for user1 > I checked for users existence and they are OK. > -- > $hay > http://scriptolog.blogspot.com > > > "RichS" <RichS@discussions.microsoft.com> wrote in message > news:52EE787C-4A4A-4C12-8E3D-89F20ED82DF9@microsoft.com... > > Does it work if you just use the second name as input? > > > > can you do a search in AD on that name & find the information? > > > > -- > > Richard Siddaway > > Please note that all scripts are supplied "as is" and with no warranty > > Blog: http://richardsiddaway.spaces.live.com/ > > PowerShell User Group: http://www.get-psuguk.org.uk > > > > > > "$hay" wrote: > > > >> I have a text file that contain user names > >> > >> users.txt > >> -------------- > >> user1 > >> user2 > >> user3 > >> > >> i use this code to get the user dn > >> > >> #============== > >> $Searcher = New-Object DirectoryServices.DirectorySearcher > >> > >> cat C:\users.txt | % { > >> $Searcher.Filter = > >> "(&(objectCategory=person)(objectClass=user)(samAccountName=$_))" > >> $usr = $Searcher.FindOne().GetDirectoryEntry() > >> $usr.distinguishedname > >> > >> # do aome other stuff based on user dn > >> } > >> > >> #============== > >> > >> > >> The first iteration returns the first user's dn, but > >> the second iteration rerurns an error > >> > >> You cannot call a method on a null-valued expression. > >> At C:\as400.ps1:62 char:46 > >> + $usr = $Searcher.FindOne().GetDirectoryEntry( <<<< ) > >> > >> > >> -- > >> $hay > >> http://scriptolog.blogspot.com > >> > >> > >> > >> > > > |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: AD Search error OK...problem solved While i was testing against some test accounts, another sys admin deleted one of them. 10x Richard, eventually your reply was in the right direction :-) -- $hay http://scriptolog.blogspot.com "RichS" <RichS@discussions.microsoft.com> wrote in message news:2243AC4C-703E-4D49-8D61-D7FC758AABD7@microsoft.com... > Do you need to recreate $Searcher each time? > -- > Richard Siddaway > Please note that all scripts are supplied "as is" and with no warranty > Blog: http://richardsiddaway.spaces.live.com/ > PowerShell User Group: http://www.get-psuguk.org.uk > > > "$hay" wrote: > >> trying manually : >> >> $Searcher = New-Object DirectoryServices.DirectorySearcher >> >> $Searcher.Filter = >> "(&(objectCategory=person)(objectClass=user)(samAccountName=user1))" >> $usr = $Searcher.FindOne().GetDirectoryEntry() >> $usr.distinguishedname >> >> $Searcher.Filter = >> "(&(objectCategory=person)(objectClass=user)(samAccountName=user2))" >> $usr = $Searcher.FindOne().GetDirectoryEntry() >> $usr.distinguishedname >> >> output: >> >> CN=user1 name,OU=Users,DC=somedomainname >> You cannot call a method on a null-valued expression. >> At C:\as400.ps1:62 char:45 >> + $usr = $Searcher.FindOne().GetDirectoryEntry( <<<< ) >> CN=user1 name,OU=Users,DC=somedomainname >> >> this always returns (in addition to the error) the dn for user1 >> I checked for users existence and they are OK. >> -- >> $hay >> http://scriptolog.blogspot.com >> >> >> "RichS" <RichS@discussions.microsoft.com> wrote in message >> news:52EE787C-4A4A-4C12-8E3D-89F20ED82DF9@microsoft.com... >> > Does it work if you just use the second name as input? >> > >> > can you do a search in AD on that name & find the information? >> > >> > -- >> > Richard Siddaway >> > Please note that all scripts are supplied "as is" and with no warranty >> > Blog: http://richardsiddaway.spaces.live.com/ >> > PowerShell User Group: http://www.get-psuguk.org.uk >> > >> > >> > "$hay" wrote: >> > >> >> I have a text file that contain user names >> >> >> >> users.txt >> >> -------------- >> >> user1 >> >> user2 >> >> user3 >> >> >> >> i use this code to get the user dn >> >> >> >> #============== >> >> $Searcher = New-Object DirectoryServices.DirectorySearcher >> >> >> >> cat C:\users.txt | % { >> >> $Searcher.Filter = >> >> "(&(objectCategory=person)(objectClass=user)(samAccountName=$_))" >> >> $usr = $Searcher.FindOne().GetDirectoryEntry() >> >> $usr.distinguishedname >> >> >> >> # do aome other stuff based on user dn >> >> } >> >> >> >> #============== >> >> >> >> >> >> The first iteration returns the first user's dn, but >> >> the second iteration rerurns an error >> >> >> >> You cannot call a method on a null-valued expression. >> >> At C:\as400.ps1:62 char:46 >> >> + $usr = $Searcher.FindOne().GetDirectoryEntry( <<<< ) >> >> >> >> >> >> -- >> >> $hay >> >> http://scriptolog.blogspot.com >> >> >> >> >> >> >> >> >> >> >> |
My System Specs![]() |
| | #6 (permalink) |
| Guest | Re: AD Search error Glad it is resolved. I was just about to post that I'd actually got round to testing your code & it worked fine. -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "$hay" wrote: > OK...problem solved > > > > While i was testing against some test accounts, another sys admin > > deleted one of them. > > > > 10x Richard, eventually your reply was in the right direction :-) > > > > -- > $hay > http://scriptolog.blogspot.com > > > "RichS" <RichS@discussions.microsoft.com> wrote in message > news:2243AC4C-703E-4D49-8D61-D7FC758AABD7@microsoft.com... > > Do you need to recreate $Searcher each time? > > -- > > Richard Siddaway > > Please note that all scripts are supplied "as is" and with no warranty > > Blog: http://richardsiddaway.spaces.live.com/ > > PowerShell User Group: http://www.get-psuguk.org.uk > > > > > > "$hay" wrote: > > > >> trying manually : > >> > >> $Searcher = New-Object DirectoryServices.DirectorySearcher > >> > >> $Searcher.Filter = > >> "(&(objectCategory=person)(objectClass=user)(samAccountName=user1))" > >> $usr = $Searcher.FindOne().GetDirectoryEntry() > >> $usr.distinguishedname > >> > >> $Searcher.Filter = > >> "(&(objectCategory=person)(objectClass=user)(samAccountName=user2))" > >> $usr = $Searcher.FindOne().GetDirectoryEntry() > >> $usr.distinguishedname > >> > >> output: > >> > >> CN=user1 name,OU=Users,DC=somedomainname > >> You cannot call a method on a null-valued expression. > >> At C:\as400.ps1:62 char:45 > >> + $usr = $Searcher.FindOne().GetDirectoryEntry( <<<< ) > >> CN=user1 name,OU=Users,DC=somedomainname > >> > >> this always returns (in addition to the error) the dn for user1 > >> I checked for users existence and they are OK. > >> -- > >> $hay > >> http://scriptolog.blogspot.com > >> > >> > >> "RichS" <RichS@discussions.microsoft.com> wrote in message > >> news:52EE787C-4A4A-4C12-8E3D-89F20ED82DF9@microsoft.com... > >> > Does it work if you just use the second name as input? > >> > > >> > can you do a search in AD on that name & find the information? > >> > > >> > -- > >> > Richard Siddaway > >> > Please note that all scripts are supplied "as is" and with no warranty > >> > Blog: http://richardsiddaway.spaces.live.com/ > >> > PowerShell User Group: http://www.get-psuguk.org.uk > >> > > >> > > >> > "$hay" wrote: > >> > > >> >> I have a text file that contain user names > >> >> > >> >> users.txt > >> >> -------------- > >> >> user1 > >> >> user2 > >> >> user3 > >> >> > >> >> i use this code to get the user dn > >> >> > >> >> #============== > >> >> $Searcher = New-Object DirectoryServices.DirectorySearcher > >> >> > >> >> cat C:\users.txt | % { > >> >> $Searcher.Filter = > >> >> "(&(objectCategory=person)(objectClass=user)(samAccountName=$_))" > >> >> $usr = $Searcher.FindOne().GetDirectoryEntry() > >> >> $usr.distinguishedname > >> >> > >> >> # do aome other stuff based on user dn > >> >> } > >> >> > >> >> #============== > >> >> > >> >> > >> >> The first iteration returns the first user's dn, but > >> >> the second iteration rerurns an error > >> >> > >> >> You cannot call a method on a null-valued expression. > >> >> At C:\as400.ps1:62 char:46 > >> >> + $usr = $Searcher.FindOne().GetDirectoryEntry( <<<< ) > >> >> > >> >> > >> >> -- > >> >> $hay > >> >> http://scriptolog.blogspot.com > >> >> > >> >> > >> >> > >> >> > >> > >> > >> > > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Search Indexer Error message | Steve | Vista General | 2 | 03-17-2008 05:05 PM |
| Desktop search - error 0x80041206 | Rein de Jong | Vista General | 0 | 01-31-2008 05:43 AM |
| Search indexer error message | Spikey | Vista General | 1 | 10-07-2007 01:40 PM |
| Windows Search Indexer error | Atanu Ghose | Vista General | 1 | 07-24-2006 12:37 AM |