Solved

Checking if User Folder Exists, if not email

Posted on 2014-12-12
2
133 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 40

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

Technology Partners: 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

This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

740 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