Solved

Checking if User Folder Exists, if not email

Posted on 2014-12-12
2
130 Views
Last Modified: 2014-12-12
Hi guys! Spent ages looking online and not found anything concrete, basically we have an active directory environment with different OU's for each sites and within each site has users in.

We have a data server with a folder for each user on (NTname format) for example test1, test2, test3 all separate folders.

I'd like to report on if a user in a particular OU has a folder on the data server or not, if it doesn't then to email advising of this. Hope this makes sense! I have a funny feeling it would be something like Get-ADUSer "Test1" and then to Test-Path if a folder exists (\\server1\users\test1"). if it doesn't exist then to email.

Thanks so much!
0
Comment
Question by:Terellion
2 Comments
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
ID: 40495899
I think you're on the right track.  Here's what I'm thinking.
$body = @(Get-ADUser -filter * | ForEach `
{
    If ( !(Test-Path "\\server\users\$($_.samaccountname)") )
    { Write-Output "Folder not found for user: $($_.samaccountname)" }
})

Send-MailMessage -To me@company.com -From script@company.com -Subject "Folder test" -Body ($body | Out-String) -SmtpServer mail.company.com

Open in new window

0
 

Author Comment

by:Terellion
ID: 40496118
That is absolutely fantastic. Precisely what I needed! THANK YOU SO MUCH :)
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

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

Suggested Solutions

Resolve DNS query failed errors for Exchange
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

947 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now