+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
Windows Thread, First Name / Last Name in Technical; Is there any script I can run to output a list of users who don't have anything in these fields ...
  1. #1

    Edu-IT's Avatar
    Join Date
    Nov 2007
    Posts
    7,457
    Thank Post
    408
    Thanked 672 Times in 614 Posts
    Rep Power
    192

    First Name / Last Name

    Is there any script I can run to output a list of users who don't have anything in these fields in AD?

  2. #2

    Ephelyon's Avatar
    Join Date
    Aug 2008
    Location
    Cheshire, England
    Posts
    1,849
    Thank Post
    350
    Thanked 392 Times in 249 Posts
    Rep Power
    162
    I'd use PowerShell's Get-ADUser command as below, searching for what you need:

    Get-ADUser

  3. #3

    Edu-IT's Avatar
    Join Date
    Nov 2007
    Posts
    7,457
    Thank Post
    408
    Thanked 672 Times in 614 Posts
    Rep Power
    192
    How would that work exactly, for finding blanks? Powershell noob here.

  4. #4


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,793
    Thank Post
    262
    Thanked 2,964 Times in 2,179 Posts
    Rep Power
    846
    I think either of the following should work...

    Code:
    Get-ADUser -LDAPFilter "(&(!(givenName=*))(!(sn=*)))"
    
    Get-ADUser -Filter {(givenName -eq $null) -and (sn -eq $null)}

  5. #5

    Ephelyon's Avatar
    Join Date
    Aug 2008
    Location
    Cheshire, England
    Posts
    1,849
    Thank Post
    350
    Thanked 392 Times in 249 Posts
    Rep Power
    162
    As we see here:

    Field Notes of a Computer Geek: Filtering for $null Values with Get-ADUser

    You can't filter for $null values. It would have to be something like this:

    Get-ADUser -Filter {(givenName -notlike "*") -and (sn -notlike "*")}

    Remember to do an "Import-Module ActiveDirectory" first though! Would've replied last night but school's Internet went down and only had the Mac here, so had nothing to play with... :P

  6. Thanks to Ephelyon from:

    Arthur (15th September 2013)

  7. #6

    Ephelyon's Avatar
    Join Date
    Aug 2008
    Location
    Cheshire, England
    Posts
    1,849
    Thank Post
    350
    Thanked 392 Times in 249 Posts
    Rep Power
    162
    On the back of that, here's a handy way to find all users who have never logged on and are not disabled:

    get-aduser -filter {(lastlogontimestamp -notlike "*")} -properties samaccountname | where { $_.enabled -eq $true} | ft samaccountname

    It's also useful that you can run PowerShell commands individually without the need to enter PowerShell every time. So from the command line or within a batch script:

    powershell -command "import-module activedirectory; get-aduser -filter {(lastlogontimestamp -notlike '*')} -properties samaccountname | where { $_.enabled -eq $true} | ft samaccountname"

    (Note that the double-quotes around the * have become single-quotes because the whole command string is now enclosed in double-quotes.)

  8. #7

    Edu-IT's Avatar
    Join Date
    Nov 2007
    Posts
    7,457
    Thank Post
    408
    Thanked 672 Times in 614 Posts
    Rep Power
    192
    Will give that a try, thanks! Is there anyway to make it output to a text file?

  9. #8

    Ephelyon's Avatar
    Join Date
    Aug 2008
    Location
    Cheshire, England
    Posts
    1,849
    Thank Post
    350
    Thanked 392 Times in 249 Posts
    Rep Power
    162
    Add on to the end of your command:

    | Out-File <path>

    So for you it might be:

    Get-ADUser -Filter {(givenName -notlike "*") -and (sn -notlike "*")} -Properties samaccountname | FT samaccountname | Out-File C:\NoNames.txt

  10. Thanks to Ephelyon from:

    Edu-IT (15th September 2013)

  11. #9


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,793
    Thank Post
    262
    Thanked 2,964 Times in 2,179 Posts
    Rep Power
    846
    Quote Originally Posted by Ephelyon View Post
    You can't filter for $null values.
    Good point. I was using my phone at the time so couldn't test. I thought it didn't look quite right.

  12. #10

    Ephelyon's Avatar
    Join Date
    Aug 2008
    Location
    Cheshire, England
    Posts
    1,849
    Thank Post
    350
    Thanked 392 Times in 249 Posts
    Rep Power
    162
    Hehe, we were both in the same position last night then. It's a bit like losing an arm when you're in the creative throes!

  13. #11

    Edu-IT's Avatar
    Join Date
    Nov 2007
    Posts
    7,457
    Thank Post
    408
    Thanked 672 Times in 614 Posts
    Rep Power
    192
    Quote Originally Posted by Ephelyon View Post
    Add on to the end of your command:

    | Out-File <path>

    So for you it might be:

    Get-ADUser -Filter {(givenName -notlike "*") -and (sn -notlike "*")} -Properties samaccountname | FT samaccountname | Out-File C:\NoNames.txt
    Thank you. Will give it a whirl tomorrow. Appreciate the help.

  14. #12

    Edu-IT's Avatar
    Join Date
    Nov 2007
    Posts
    7,457
    Thank Post
    408
    Thanked 672 Times in 614 Posts
    Rep Power
    192
    Worked a treat and was such a timesaver. :-)

  15. #13

    Ephelyon's Avatar
    Join Date
    Aug 2008
    Location
    Cheshire, England
    Posts
    1,849
    Thank Post
    350
    Thanked 392 Times in 249 Posts
    Rep Power
    162
    No worries Is it so you can add names in for those without them?

  16. #14

    Edu-IT's Avatar
    Join Date
    Nov 2007
    Posts
    7,457
    Thank Post
    408
    Thanked 672 Times in 614 Posts
    Rep Power
    192
    That is correct. Yes.

  17. #15

    Ephelyon's Avatar
    Join Date
    Aug 2008
    Location
    Cheshire, England
    Posts
    1,849
    Thank Post
    350
    Thanked 392 Times in 249 Posts
    Rep Power
    162
    If usernames already have some semblance to personal data stored in SIMS, would you be interested in a bolt-on that pulls out the relevant details from the MIS and populates those user fields automatically, tying the whole thing together?



SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Adding in first name and last name into AD general tab
    By Disease in forum How do you do....it?
    Replies: 2
    Last Post: 19th October 2012, 11:05 PM
  2. Find my internal domain name/realm name?
    By Miscbrah in forum Windows Server 2008
    Replies: 2
    Last Post: 2nd May 2012, 11:12 AM
  3. Don't display last user name Win7 /Server 2008 R2 - HELP!!!
    By bewlay51 in forum Windows Server 2008 R2
    Replies: 6
    Last Post: 5th August 2010, 09:05 AM
  4. Moodle Hide First Name
    By TechMonkey in forum Virtual Learning Platforms
    Replies: 2
    Last Post: 19th November 2009, 10:31 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •