so this is the next level… with one more step to add later on…

and remember this is me beginning to play with powershell i am sure there are nicer ways to code…

this will check a users properties for the homedirectory attribute and then scan their home directory and see what files have not been used in the last 30days and write the results out to a csv file

I plan to add to this script but this is the core of it so far…


import-module ActiveDirectory
write-host "Checking For HomeDirectory"
$enabledusers = get-aduser -filter {Enabled -eq "True"} -properties Homedirectory |where {$_.HomeDirectory -ne $null}

Foreach ($u in $enabledusers)
    $pathtocheck = $u.homedirectory

    $statuscheck = get-childitem $pathtocheck -Recurse

    Foreach ($s in $statuscheck)


    $access = $s | % {(get-date) – $_.LastAccessTime }
        if ($access.days -ge 2)
        write-host $s.fullname
        write-host "File Was Last Accessed" $access.days "Days Ago"
        $s |format-table -property Fullname |out-file c:\results.csv -append