?
Solved

Modifying PowerShell to list home drives of disabled users ?

Posted on 2016-09-27
6
Medium Priority
?
91 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
Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

777 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