I am trying to find orphaned user directory. I have already exported users, disabled users, users without the directory path. I found this online but it not working. any thoughts?<\/p>\n
[CmdletBinding()] if ($ADResult)<\/p>\n try{ $HashProps = [PSCustomObject]@{ } elseif (([boolean]((-join $ADResult.Properties.useraccountcontrol) -band 2))) { I am trying to find orphaned user directory. I have already exported users, disabled users, users without the directory path. I found this online but it not working. any thoughts?<\/p>\n [CmdletBinding()] if ($ADResult)<\/p>\n try{ $HashProps = [PSCustomObject]@{ } elseif (([boolean]((-join $ADResult.Properties.useraccountcontrol) -band 2))) { My fist thought is to please use the insert code button.<\/p>\n My second thought it, what is the error you are getting or what exactly is not working?<\/p>\n If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n
\nparam(
\n[string]$HomeFolderPath = ’
\n)
\nGet-ChildItem -LiteralPath “$HomeFolderPath” -Force | Where-Object {$.PSIsContainer} | ForEach-Object {
\nTry{
\n$CurrentPath = Split-Path -Path $<\/em> -Leaf
\n$ADResult = ([adsisearcher]“(samaccountname=$CurrentPath)”).Findone()<\/p>\n
\n$ouIndex = $($ADResult.Properties.distinguishedname).IndexOf(‘OU=’)
\n$OU = ($ADResult.Properties.distinguishedname).Substring($ouIndex)
\n}
\ncatch{
\nWrite-Warning -Message \"Object $($ADResult.Properties.distinguishedname) is in a Container. \"
\n$OU=‘Default Container’
\n}<\/p>\n
\n‘SamAccountName’ = $CurrentPath
\n‘Name’ = $($ADResult.Properties.name)
\n‘FullPath’ = $.FullName
\n‘HomeDirectory’ = $($ADResult.Properties.homedirectory)
\n‘Manager’ = $manager
\n‘Location’ = $($ADResult.Properties.l)
\n‘Department’ = $($ADResult.Properties.department)
\n‘Account Status’ = $status
\n‘OU’ = $OU
\n}
\n}
\nElse {
\n$HashProps = [PSCustomObject]@{
\n‘SamAccountName’ = $CurrentPath
\n‘Name’= ‘N/A’
\n‘FullPath’ = $<\/em>.FullName
\n‘HomeDirectory’ = ‘N/A’
\n‘Manager’ = ‘N/A’
\n‘Location’ = ‘N/A’
\n‘Department’ = ‘N/A’
\n‘Account Status’ = ‘Non-Existent’
\n‘OU’ = ‘N/A’
\n}
\n}
\n}
\ncatch {
\nWrite-Warning $_
\n}
\nfinally{
\n#write<\/span> output $HashProps
\n$HashProps
\n}
\n}<\/p>\n
\n$HashProps = @{
\n‘Error’ = ‘Account is disabled and has a home folder’
\n‘FullPath’ = $_.FullName
\n}
\nexport-csv “c:\\ophhome.csv” -NoTypeInformation<\/p>","upvoteCount":7,"answerCount":9,"datePublished":"2019-05-16T18:17:02.000Z","author":{"@type":"Person","name":"timzimmerman2","url":"https://community.spiceworks.com/u/timzimmerman2"},"suggestedAnswer":[{"@type":"Answer","text":"
\nparam(
\n[string]$HomeFolderPath = ’
\n)
\nGet-ChildItem -LiteralPath “$HomeFolderPath” -Force | Where-Object {$.PSIsContainer} | ForEach-Object {
\nTry{
\n$CurrentPath = Split-Path -Path $<\/em> -Leaf
\n$ADResult = ([adsisearcher]“(samaccountname=$CurrentPath)”).Findone()<\/p>\n
\n$ouIndex = $($ADResult.Properties.distinguishedname).IndexOf(‘OU=’)
\n$OU = ($ADResult.Properties.distinguishedname).Substring($ouIndex)
\n}
\ncatch{
\nWrite-Warning -Message \"Object $($ADResult.Properties.distinguishedname) is in a Container. \"
\n$OU=‘Default Container’
\n}<\/p>\n
\n‘SamAccountName’ = $CurrentPath
\n‘Name’ = $($ADResult.Properties.name)
\n‘FullPath’ = $.FullName
\n‘HomeDirectory’ = $($ADResult.Properties.homedirectory)
\n‘Manager’ = $manager
\n‘Location’ = $($ADResult.Properties.l)
\n‘Department’ = $($ADResult.Properties.department)
\n‘Account Status’ = $status
\n‘OU’ = $OU
\n}
\n}
\nElse {
\n$HashProps = [PSCustomObject]@{
\n‘SamAccountName’ = $CurrentPath
\n‘Name’= ‘N/A’
\n‘FullPath’ = $<\/em>.FullName
\n‘HomeDirectory’ = ‘N/A’
\n‘Manager’ = ‘N/A’
\n‘Location’ = ‘N/A’
\n‘Department’ = ‘N/A’
\n‘Account Status’ = ‘Non-Existent’
\n‘OU’ = ‘N/A’
\n}
\n}
\n}
\ncatch {
\nWrite-Warning $_
\n}
\nfinally{
\n#write<\/span> output $HashProps
\n$HashProps
\n}
\n}<\/p>\n
\n$HashProps = @{
\n‘Error’ = ‘Account is disabled and has a home folder’
\n‘FullPath’ = $_.FullName
\n}
\nexport-csv “c:\\ophhome.csv” -NoTypeInformation<\/p>","upvoteCount":7,"datePublished":"2019-05-16T18:17:03.000Z","url":"https://community.spiceworks.com/t/orphaned-user-directory/712360/1","author":{"@type":"Person","name":"timzimmerman2","url":"https://community.spiceworks.com/u/timzimmerman2"}},{"@type":"Answer","text":"