• SCOM 2012 Documentation
  • Microsoft OpsMgr Team Blog
  • Kevin Holman’s Blog
  • thoughtsonopsmgr
  • SCOM2K7 Blog
  • BICTT Blog
  • Cameron Fuller
  • JC’s SCOM Blog
  • Tao Yang SCOM Blog
SCOM GOD

AD Password Expiration Report Script

November 5, 2013 9:00 pm / Leave a Comment / SCOMGod

Can someone make this PowerShell? :) It works great as it is but CDO is such a drag. Enjoy!

‘Script to list all password that will list
‘all accounts with passwords expiring within the next 30 days

On Error Resume Next

Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
Const ONE_HUNDRED_NANOSECOND = .000000100
Const SECONDS_IN_DAY = 86400
DayCount = 30
OUtoSearch = “OU=NY”

Set OFSO = CreateObject(“Scripting.FileSystemObject”)

nof = “E:\logs\AcctsToExp.txt”

If OFSO.FileExists (nof) Then
OFSO.DeleteFile(“E:\logs\AcctsToExp.txt”)
End If

If not OFSO.FileExists (nof) Then
Set objFile = OFSO.CreateTextFile(nof)
End If

‘Const ForAppending = 8
‘Set objFile = OFSO.OpenTextFile (nof, ForAppending)
objFile.WriteBlankLines (1)
objFile.WriteLine “Passwords due to expire in the” & ” ” & OUtoSearch & ” OU” & ” during the next ” & DayCount & ” Days” & vbTab & vbTab & Now
objFile.WriteLine

Set objConnection = CreateObject(“ADODB.Connection”)
objConnection.Open “Provider=ADsDSOObject;”
Set objCommand = CreateObject(“ADODB.Command”)
objCommand.ActiveConnection = objConnection
objCommand.CommandText = “;” & “(&(objectCategory=person) (objectClass=User));” & _
“userAccountControl,distinguishedName,sAMAccountName,cn;subtree”

‘objCommand.CommandText = “;” & “(&(objectCategory=person) (objectClass=User));” & _
‘”userAccountControl,distinguishedName,sAMAccountName,cn;subtree”

‘-objCommand.CommandText = “;(objectCategory=User)” & _
‘- “;userAccountControl,distinguishedName,sAMAccountName;subtree”
objCommand.Properties(“Page Size”) = 4000
objCommand.Properties(“Timeout”) = 90
objCommand.Properties(“Cache Results”) = True
Set objRecordSet = objCommand.Execute

intCounter = 0
‘wscript.echo objRecordset.RecordCount
If objRecordset.RecordCount > 0 then
objRecordset.MoveFirst
end if

Do Until objRecordset.EOF
Uname = objRecordset.Fields(“distinguishedName”)
ShName = objRecordset.Fields(“sAMAccountName”)
Namelenght = Len(ShName)
SpacesToAdd = 15 – NameLenght
DisplayName = ShName & Space(SpacesToAdd)
Set objUser = GetObject(“LDAP://” & Uname )
intUserAccountControl = objUser.Get(“userAccountControl”)
If intUserAccountControl And ADS_UF_DONT_EXPIRE_PASSWD Then
‘objFile.WriteLine DisplayName & vbTab & vbTab & “The password does not expire.”
Else
dtmValue = objUser.PasswordLastChanged
intTimeInterval = Int(Now – dtmValue)
Set objDomain = GetObject(“LDAP://DC=myco,DC=com”)
Set objMaxPwdAge = objDomain.Get(“maxPwdAge”)
If objMaxPwdAge.LowPart = 0 Then
objFile.WriteLine DisplayName & vbTab & vbTab & “The Maximum Password Age is set to 0, Password does not expire.”
Else
dblMaxPwdNano = Abs(objMaxPwdAge.HighPart * 2^32 + objMaxPwdAge.LowPart)
dblMaxPwdSecs = dblMaxPwdNano * ONE_HUNDRED_NANOSECOND
dblMaxPwdDays = Int(dblMaxPwdSecs / SECONDS_IN_DAY)
End If
If intTimeInterval >= dblMaxPwdDays Then
objFile.WriteLine DisplayName & vbTab & vbTab & “The password has expired.”
Else
If Int((dtmValue + dblMaxPwdDays) – Now) < DayCount Then objFile.WriteLine DisplayName & vbTab & vbTab & "The password will expire on " & DateValue(dtmValue + dblMaxPwdDays) & " (" & Int((dtmValue + dblMaxPwdDays) - Now) & " days from today)." End If End If End If intCounter = intCounter + 1 objRecordset.MoveNext Loop objConnection.Close objfile.close OFSO.Close '==================================================== 'EMAIL Routine '==================================================== Set objMessage = CreateObject("CDO.Message") objMessage.Subject = "Password Expiration Report For New York Office" objMessage.From = "PASSWORD-EXPIRATION@myco.com" objMessage.To = "SupportSupervisors@myco.com" objMessage.TextBody = "Password expiration for New York Attached" objMessage.AddAttachment "e:\logs\acctstoexp.txt" '==This section provides the configuration information for the remote SMTP server. '==Normally you will only change the server name or IP. objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Name or IP of Remote SMTP Server objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.myco.com" 'Server port (typically 25) objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objMessage.Configuration.Fields.Update '==End remote SMTP server configuration section== objMessage.Send

Posted in: Scripts

Leave a Reply Cancel reply

You must be logged in to post a comment.

Post Navigation

← Previous Post
Next Post →

Recent Comments

  • admin on SCOM SQL Script to show gray agent data historical reasons
  • admin on SCOM SQL Script to show gray agent data historical reasons
  • Gene on SCOM SQL Script to show gray agent data historical reasons
  • admin on SCCM 2012 SP1 Installation Pre-reqs
  • Ryan on SCCM 2012 SP1 Installation Pre-reqs

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Blogroll

  • Anders Blog
  • Daniele's Blog
  • Great SCOM Report Tutorial
  • Microsoft SCOM Forums
  • Savision Sample Dashboards
  • SCOM Blog
  • SCOM FAQ
  • scom-2012.blogspot.be
  • System Center 2012 Notes From the Field
  • Veam Install PDF

Recent Posts

  • PowerShell Script RDP Sessions List
  • Powershell Search Thru IIS Logs for Text String
  • PowerShell Reboot AD Based Computers
  • PowerShell Dump ACL of a Path Folder
  • SCOM Maintenance Mode Group of Servers
  • WMI Admin Access without Domain Admin Privilege
  • Script to Update User Redirected Folders ACL
  • Windows 2012 R2 Folder Redirection Step by Step
  • SharePoint 2013 Pre-reqs Link
  • Windows 2012 TSAdmin Download
  • Server Reboot Batch File
  • SCOM Get Missing Performance Data
  • SCOM 2012 Linux Agent gray and critical – Requires uninstall of agent & cert
  • SCOM 2012 Batch File to Clear Health Service Cache
  • SCOM 2012 Put URL into Maintenance Mode
  • MS Operations Management Suite Survival Guide
  • Script to Logoff All Disconnected Citrix Sessions
  • SCOM 2012 R2 Close All Alerts Script
  • SCOM Health Service Flush Scripts
  • SCOM 2012 PowerShell One Liners
  • GreenMachine for SCOM 2012
  • VBS Script to get AD Group Members
  • SCOM 2012 Maintenance Mode Notification MP
  • SCOM 2012 Reminder Alerts – PowerShell Script to Update Alert Resolution
  • SCOM 2012 R2 Test Event MP
  • SCOM Cluster Failover Events MP
  • SCOM 2012 R2 Maintenance Mode Powershell Script for Single Server
  • SCOM Reports Edit Issue QFE_MOMEsc_4724
  • Clean Windows 2008R2 Space
  • SCOM Linked Availability Report
  • SCOM Catch All Management Pack
  • PowerShell Script Close All SCOM Alerts 2007R2
  • Windows Update Error 80072EFE in Client Hyper-V Guest
  • SCOM query to get all data about an obejct
  • SCOM 2012 Cluster Disks management pack addendum
  • SCOM Cluster CSV Query
  • SCOM REPORT MODELS
  • SCOM 2012 Bulk URL Editor Manager Download
  • SCOM Catch All Error Events Log Rule
  • SCOM 2012 iSCSI Volume Shadow Copy Rules MP
  • Configuring Hyper-V for multiple subnets with only one NIC (Server 2012 R2 Edition)
  • Windows 2012 USB Boot Disk
  • SCOM Web Console Path Not Showing
  • Windows 2012 R2 BlueScreen Fix
  • AD Password Expiration Report Script
  • SCCM Query: Uptime and Last Reboot Time
  • SCOM 2012 ToolBox Downloads
  • EMC SCOM 2012 Management Pack ESI
  • SCOM ETL Trace Instructions
  • Extended SQL MP
  • SQL Instance List Report for SCOM
  • SCOM SQL Script to show gray agent data historical reasons
  • List of all SCOM Monitors from Various Popular Management Packs
  • How to extend date of SCOM certificate issued by Stand Alone CA
  • How to Run Hyper-V on a Laptop
  • SCOM Alert for Specific Account lockout
  • Microsoft Technet Lab Guides
  • SCOM Gateway Troubleshooting Steps – Jonathan Cowan Credit
  • SCOM 2012 Maintenance Mode Utility
  • How to Reinstall SCOM Reporting
  • SCCM 2012 Client Action Tool!
  • SCOM Report Data Source Fix
  • SCOM 2012 Health Check Script
  • SCOM RunAs Account Fixer PowerShell Script!
  • File Share Check and Email Script
  • SCOM 2012 Exchange 2010 MP Filling Logs with Login Failures
  • SCOM 2012 Report Data Source Option Missing
  • SCOM 2012 File Share Management Pack
  • Dynamic Groups with Expressions in OpsMgr
  • SCOM 2012 Unsealed Management Pack Backup
  • SCOM 2012 Web View Widget
  • Windows 2003 Bits 2.5 Download
  • SCOM 2012 Maintenance Mode
  • SCOM 2012 Utilization Reports Processor Data Missing
  • Windows Server 2012 Keyboard Shortcuts
  • SQL SCOM 2012 Alerts By Email Script
  • Windows 2012 Interface Explanation from Microsoft
  • Microsoft Private Cloud Step By Step
  • Managing SCOM 2012 Alerts: Daily Tasks
  • SCOM 2012 Training Guides and Videos
  • SCCM 2012 SP1 Installation Pre-reqs
  • SCOM SQL Run As Account Guidelines
  • Windows Server 2012 Won’t Activate: DNS Server Not Found
  • Brian Wren’s Sample Network Management Pack for System Center 2012 Operations Manager
  • The Greatest PowerShell Script of All Time for Windows Admins by Sean Duffy
  • SCOM Health Check Excel Template
  • List All AD User Object Attributes
  • Sharepoint 2010 Management Pack for SCOM 2012
  • How to Run a Powershell Script as a rule in SCOM as a Command
  • OpsLogix PING MP for SCOM 2012
  • SQL Server cannot authenticate using Kerberos because the Service Principal Name (SPN) is missing, misplaced, or duplicated.
  • SCOM Maintenance Mode EXE – Awesome Utility
  • SCOM Grey Agent MP from SCC
  • The All Management Servers Pool has not reported availability
  • SCOM ACS Filter Events
  • SCOM ACS Modified SQL Stored Procedures
  • MMS 2012 Session Listing Download
  • SQL Database Stuck in Restoring Mode
  • SCOM Maintenance Mode Script
  • SCOM Active Directory Security Management Pack
April 2021
M T W T F S S
« Apr    
 1234
567891011
12131415161718
19202122232425
2627282930  

About

This site is a collection of tools and tips that I needed to place in the cloud. I have given credit where credit is due and respect all the hard work of those in the SCOM community that are miles above me in terms of knowledge, experience and accolades.
© Copyright 2021 - SCOM GOD
Infinity Theme by DesignCoral / WordPress