Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

PowerShell to check files and send e-mail notification

$
0
0

Hello Experts,

I am fairly new to PowerShell, but must say I am impressed by what the tool can accomplish, so I expect to learn a great deal more and become more proficient as time goes on.

Scenario:

I need to check if a certain file exists, was created today, and actually has content.

  • If the file does not exist, or was not created today, an e-mail should be sent that states "File not created" or similar.
  • If the file exists and was created today, but has no content, no e-mail should be sent.
  • If the file exists, was created today, and has content an e-mail should be sent that has the contents of the file in the body of the e-mail.

Reason for this request:

I have to check (and keep in sync) user account status (enabled/disabled) in two Active Directory forrests, for which we unfortunately cannot set up a trust. One is the corporate directory (I'll call it directory A) and the other is a separate forrest used to control system access at one of our facilities (I'll call that directory B). The authoritative directory is directory A. Directory B is managed separately, but contains a subset of the users in directory A, so the user accounts match up to a certain extent. When a user account is disabled in directory A, I need to ensure that the corresponding user account in directory B is also disabled (if the user has an account in directory B that is). I figured out how to automate creating a list of accounts that have been disabled in directory A, but are still active in directory B, (that was fun :-)), but rather than rely on someone to run this manually I would like to automate this solution to run daily and send the e-mails referenced above to whomever needs to receive them.

 

For this example:

  • Folder path = c:\Compare_AD
  • File to check for = Accounts_To_Check.txt
  • smtp server = smtp.mailitsomewhere.net

Any assistance you could offer would be greatly appreciated.

Regards

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles