List of homedirs without a user

Welcome Forums General PowerShell Q&A List of homedirs without a user

This topic contains 2 replies, has 2 voices, and was last updated by

2 years, 2 months ago.

  • Author
  • #56618

    Points: 0
    Rank: Member

    I need a script to show a list of home directories that do not have a user assigned to them, this part was fairly easy. Where I am having trouble is sometimes we have a home directory without the original user but someone else has been assigned to it when the user left. I am trying to clear all of these up. I was able to get a list of HomeDirs without the original owner but now want to see which of those may have another user added to it. For the second part I am using Get-Acl to find who has rights but that lists all of our normal accounts that have access to everything.
    I need a way to do a Where -eq anything except what is in the "exceptions list". This is what I have so far:

    Add-PSSnapin Quest.ActiveRoles.ADManagement
    $Exceptions = @("BUILTIN","ADMINUser","Domain Admins","Enterprise Admins","migrationadmin")
    dir \\MYFILESERVER\users\ | Where {$_.PSIsContainer -AND -not (Get-QADUser -SearchRoot "MYOUPath" -SamAccountName $_.PSChildName)} | get-acl| ForEach {
     $_ | select -expand access | 
     where {$_.identityreference -notmatch $Exceptions} |
     Select @{Name="Path";Expression={$Path}},IdentityReference,FileSystemRights

    This gets me a list of homedirs without users but ignoring the exceptions.
    I know my problem is with this line:

    where {$_.identityreference -notmatch $Exceptions}

    but being so new to powershell I am just not sure how to do it.


  • #56621

    Points: 21
    Rank: Member

    try -notin instead of -notmatch.

    • #56627

      Points: 0
      Rank: Member

      That did it and actually makes sense now 🙂
      Thanks alot!

The topic ‘List of homedirs without a user’ is closed to new replies.