Solved

Checking if User Folder Exists, if not email

Posted on 2014-12-12
2
129 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
Comment Utility
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
Comment Utility
That is absolutely fantastic. Precisely what I needed! THANK YOU SO MUCH :)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Resolve DNS query failed errors for Exchange
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 to another domain controller. Log onto the new domain controller with a user account t…

771 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

9 Experts available now in Live!

Get 1:1 Help Now