Solved

need a powershell or quest AD cmdlets script to send out an HTML attachment

Posted on 2014-01-06
8
536 Views
Last Modified: 2014-01-08
can someone provide a powershell or AD Cmdlets script that we can use to check Active Directory daily to find out what passwords will expire in the next 14 days, and send out an email notice using an html file with variables in it?

many thanks

S.
0
Comment
Question by:siber1
  • 3
  • 2
8 Comments
 
LVL 69

Accepted Solution

by:
Qlemo earned 250 total points
ID: 39761472
Don't know what you mean with "variables in it", but that is my approach:
Add-PsSnapIn Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue 
$body = `
Get-QADUser -Enabled -SizeLimit 0 | Select-Object samAccountName, mail, PasswordStatus |  
  ? {"Password never expires", "Expired", "User must change password at next logon." -notcontains $_.PasswordStatus} |  
  % { 
    $passwordexpiry = $passwordstatus.Replace("Expires at: ","") 
    $daysremaining  = ((get-date $passwirdexpiry) - (get-date)).Days
    if ($daysremaining -le 14) {
      $_ | Add-Member NoteProperty 'DaysRemaining' $daysremaining -PassThru
  } | convertTo-HTML
Send-MailMessage -SmtpServer mail.yourdomain.com `
                 -From       HelpDesk@yourdomain.com `
                 -To         HelpDesk@yourdomain.com `
                 -Subject    'Daily Pwd Expiry Report' `
                 -Body       $body -bodyAsHtml

Open in new window

0
 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 250 total points
ID: 39761479
0
 

Author Closing Comment

by:siber1
ID: 39765708
thank you Subsun and Qlemo. both solutions will work fine for us.

S.
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
LVL 40

Expert Comment

by:Subsun
ID: 39766001
Qlemo,  let's agree to disagree!!.. :) .. I didn't post just a link to discussion thread from any other forum.. Moreover I don’t think it’s too cumbersome for an AD administrator to understand what is written in the article as it is very direct an instructive..

The thread which you are referring to have only few comments which referring to the specific code which is used to send HTML email for the users who’s password is going to expire. I agree that posting links is not a good thing to do but, I just didn't want to copy paste the code from the article. If OP have further questions then I would have happy assisted him to update the code..

BTB, Get-QADuser won’t work to find the password expiry date in all scenarios, for instance if you have a windows 2008 R2 or later domain and you have some  fine-grained password policies then you need to use the function Get-XADUserPasswordExpirationDate to find the exact password expiry date of the user.

@siber1, If you have used Qlemo's solution to achieve your goal, then you may request to reopen he question so that the points can be awarded to correct solution, I am ok with it..
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39766119
Got it.. will keep it in mind..
0
 

Author Comment

by:siber1
ID: 39766934
Qlemo,
I'm not going to get caught up in the politics of this, but I will say that you are extremely fortunate to have someone the caliber of Subsun posting answers to our questions. He is extremely knowledgeable and his advise and postings are the main reason I subscribe to your service.

Michael aka @siber
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

726 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