Sometime i love to run scripts manually and sometime  i like to schedule them. In our company we have lots of new joiners every week, and we also creates and use AD groups. In our IT team not everyone known about which users has just joined the company recently.

To ensure everyone in IT team knows about a new joiner in the company i have written a Tiny-Miny powershell script which is scheduled to run on every monday. This script send a HTML formatted email containing the list of New AD Users and New AD groups those are created within a 7 days,.


For more info visit this link : http://newdelhipowershellusergroup.blogspot.in/2012/10/script-to-send-html-formatted-email-of.html

Best Regards!

Aman Dhally 

Come and join my journey of 100 Days of Self Improvement programme: https://www.facebook.com/100DoSI or at www.amandhally.net   

MY PowerShell Blog : http://newdelhipowershellusergroup.blogspot.com/ 

MY Personal Website: www.amandhally.net



            " Satnaam WaheGuru Ji"     
            Author  :  Aman Dhally 
            E-Mail  :  amandhally@gmail.com 
            website :  www.amandhally.net 
            twitter :  https://twitter.com/#!/AmanDhally 
            facebook:  http://www.facebook.com/groups/254997707860848/ 
            Linkedin:  http://www.linkedin.com/profile/view?id=23651495 
            Date    :  29-10-2012 
            File    :  AD and user Reporting 
            Purpose :   
            Version : 1 
#Setting Date of One Week Back 
$week = (Get-Date).AddDays(-7) 
$today = (Get-Date).ToString() 
# Html 
$a = "" 
# Email Variables 
$smtp = "Exchange-Delhi" 
$to = "AmanDhally@gmail.com"  
$from = "Scripts<Scripts@XyZ.com>" 
$subject = "New AD Users & Groups Created Last Week." 
# Import Module of Active Directory 
Import-Module -Name ActiveDirectory 
# Run Command  
$Users = Get-ADUser -Filter * -Properties * | ` 
    where { $_.whenCreated -ge $week }  | sort | select Name,WhenCreated  ` 
                                          | ConvertTo-html -Head $a -Body "<H2>Users Created this Week.</H2>" 
#  Group 
$group = Get-ADgroup -Filter * -Properties * | ` 
    where { $_.whenCreated -ge $week } | sort |select Name,whenCreated ` 
                                          | ConvertTo-html -Head $a -Body "<H2>Groups Created this week..</H2>" 
$body = "Creation period from $week to $today ." 
$body +"`n" 
$body +$Users 
$body +"`n" 
$body +$group 
$body +"`n" 
Send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml