• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 105
  • Last Modified:

Modifying PowerShell to list home drives of disabled users ?

Hi All,

Can anyone here please help me to modify the script below:

Get-Content D:\Temp\DisabledAccounts.txt | % {If ($Path = Get-Item "\\<Server>\<Share>\$($_)" -ea si) {Rename-Item -Path $Path.FullName -NewName "_Old_$($Path.Name)" -WhatIf}} 

Open in new window


So that it can go through AD OU and then list the directory to be deleted in the separate file server ?

Disabled OU location: OU=Disabled USERS,OU=Main Office,DC=domain,DC=com
File Server Location: \\FileServerHQ\Users


Thanks in advance.

Note:
I've found it from: https://www.experts-exchange.com/questions/28963489/Looking-for-a-way-to-find-if-the-AD-disabled-accounts-have-HOME-folders-in-a-specific-CIFS-share.html
0
Senior IT System Engineer
Asked:
Senior IT System Engineer
  • 4
  • 2
1 Solution
 
SubsunCommented:
To get all users with HomeDirectory from a OU
Get-ADUser -SearchBase "OU=Disabled USERS,OU=Main Office,DC=domain,DC=com" -F * -Pr HomeDirectory | ?{$_.HomeDirectory} | Select Name,HomeDirectory | Export-CSV C:\report.csv -nti

Open in new window

To get all users with HomeDirectory on \\FileServerHQ\Users from a OU
Get-ADUser -SearchBase "OU=Disabled USERS,OU=Main Office,DC=domain,DC=com" -F * -Pr HomeDirectory | ?{$_.HomeDirectory -match "^\\\\FileServerHQ\\Users"} | Select Name,HomeDirectory | Export-CSV C:\report.csv -nti

Open in new window

1
 
Senior IT System EngineerIT ProfessionalAuthor Commented:
Subsun,

Many thanks for the code, so is it possible to get the "orphaned" directory as well where the AD account is already deleted ?
0
 
SubsunCommented:
Yes, If your how folder share is in format \\Server\Users\<User sAMAccountName >

you can get the user sAMAccountName from the home folder path and check if user exist or not. If the user account doesn't exist in AD then the folder can be considered as orphaned.

For this you need to read all home folders and run the query against each home folder, that should be a separate script..
1
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Senior IT System EngineerIT ProfessionalAuthor Commented:
Yes, the format is \\Server\Users\<User sAMAccountName >

I will post separate thread for this request.
0
 
Senior IT System EngineerIT ProfessionalAuthor Commented:
0
 
Senior IT System EngineerIT ProfessionalAuthor Commented:
Thanks !
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now