header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Get-ADUser Homedirectory weirdness
Last Post 26 Nov 2009 05:10 AM by Spad. 0 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
SpadUser is Offline
New Member
New Member
Posts:3
Avatar

--
26 Nov 2009 05:10 AM
    I've been trying to write a short Powershell script to check for orphaned home drives and found that it was returning way too many results.

    The basic syntax is

    import-module ActiveDirectory

    $path = "\\path\"
    $file = New-Item -type file "C:\unusedhome.txt"
    $homedrives = Get-ChildItem $path

    ForEach($folder in $homedrives){
    $name = $path + $folder.name
    $user = Get-ADUser -Filter { HomeDirectory -eq $name }

    if($user -eq $null){
    add-content $file $name
    }
     
    $user = $null
    }

    It appears that every account with a samaccountname starting with 0 through 9 and A through F returns null, whereas everything account with a samaccountname starting with G through Z returns a result (where it should).

    The weirdest thing is that even if I use something like

    $user = Get-ADUser "bob" -Properties HomeDirectory
    Get-ADUser -Filter { HomeDirectory -eq $user.homedirectory }

    Where "bob" is a user with a homedirectory set, it still returns null, even though $user.homedirectory contains the correct homedirectory value as read out of the user account .

    Any ideas?
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer