Solved

Checking if User Folder Exists, if not email

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
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…
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 …

856 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