?
Solved

Modifying PowerShell to list home drives of disabled users ?

Posted on 2016-09-27
6
Medium Priority
?
94 Views
Last Modified: 2016-09-27
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
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 41817693
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
 
LVL 8

Author Comment

by:Senior IT System Engineer
ID: 41817743
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
 
LVL 40

Expert Comment

by:Subsun
ID: 41817798
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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 8

Author Comment

by:Senior IT System Engineer
ID: 41818879
Yes, the format is \\Server\Users\<User sAMAccountName >

I will post separate thread for this request.
0
 
LVL 8

Author Comment

by:Senior IT System Engineer
ID: 41819014
0
 
LVL 8

Author Closing Comment

by:Senior IT System Engineer
ID: 41819015
Thanks !
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question