password never expires

<#

This script find all the users whose passwords never expire and send a report to mail.
Idit Bnaya

#>

Import-Module activedirectory
$date=Get-Date
$date1 = $date.ToShortDateString()
$date2 = $date1.Replace("/","_")
$FolderPath = ‘c:\temp’
 
Get-ADUser -filter * -Properties PasswordNeverExpires | where {($_.PasswordNeverExpires -eq $true)}  |select name,SamAccountName,DistinguishedName,PasswordNeverExpires |Export-Csv $folderpath\"passnerverexpired"’  ‘$date2.csv

$smtpServer = "SMTP Address"
$smtpFrom = "ReportPasswordneverexpired@idit.com"
$smtpTo = "idit.bnaya@iditbnaya.com"
$messageSubject = "PasswordNeverExpired "+" "+$date

Send-MailMessage -To $smtpTo -From $smtpfrom -SmtpServer $smtpServer -Subject $messageSubject -BodyAsHtml -Attachments $folderpath\"passnerverexpired"’  ‘$date2.csv

About Idit Bnaya

Sr. Cloud Solution Architect at Microsoft, I’m passionate about helping customers succeed by building secure, scalable, and innovative cloud solutions – with a strong focus on AI, DevOps practices, and end-to-end security. With a proven track record in the IT and services industry, I serve as a trusted advisor, partnering closely with organizations to guide them through digital transformation and maximize the value of their cloud investments. My role combines technical leadership with project ownership – from designing modern architectures to leading cross-functional implementations that drive real business outcomes. I also manage and empower strategic partners, working hand-in-hand with them to ensure project success and deliver measurable business impact for customers.
This entry was posted in PowerShell and tagged , . Bookmark the permalink.

Leave a Reply