NexOps

AI-powered automations, scripts, and tools that solve real IT problems. Stop doing things manually — let machines handle it.
Location hidden
•Created byProfile pictureqiao sheng
1 joined
Profile picture
qiao shengProfile picture@qiaoapplejuiceĀ·Apr 22

šŸ”” Free Script: AD Password Expiry Notifier (PowerShell)

Every helpdesk team deals with this: users call in because their password expired and they didn't know it was coming. This script checks Active Directory and emails users 7, 3, and 1 day before expiry.


Set it as a scheduled task and watch password reset tickets drop.


---


The Script


# AD Password Expiry Notifier
# Run as scheduled task daily at 8 AM

Import-Module ActiveDirectory

$SmtpServer = "smtp.yourdomain.com"
$FromAddress = "it-notifications@yourdomain.com"
$WarningDays = @(7, 3, 1)
$MaxPasswordAge = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.Days

$Users = Get-ADUser -Filter {
    Enabled -eq $true -and 
    PasswordNeverExpires -eq $false
} -Properties Mail, PasswordLastSet, DisplayName

foreach ($User in $Users) {
    if (-not $User.Mail -or -not $User.PasswordLastSet) { continue }
    
    $ExpiryDate = $User.PasswordLastSet.AddDays($MaxPasswordAge)
    $DaysLeft = ($ExpiryDate - (Get-Date)).Days
    
    if ($DaysLeft -in $WarningDays) {
        $Subject = "āš ļø Your password expires in $DaysLeft day(s)"
        $Body = @"
Hi $($User.DisplayName),

Your network password will expire on $($ExpiryDate.ToString('dddd, MMMM dd, yyyy')).

To change it:
1. Press Ctrl + Alt + Delete
2. Click 'Change a password'
3. Enter your current password and choose a new one

If you're remote, connect to VPN first.

Questions? Contact the helpdesk.

- IT Team
"@
        
        Send-MailMessage -To $User.Mail -From $FromAddress `
            -Subject $Subject -Body $Body -SmtpServer $SmtpServer
        
        Write-Host "Notified: $($User.DisplayName) — $DaysLeft days left"
    }
}

Write-Host "Done. Password expiry check complete."


---


Setup


  1. Save as PasswordExpiryNotifier.ps1

  2. Update $SmtpServer and $FromAddress with your mail settings

  3. Create a Windows Scheduled Task to run daily at 8 AM

  4. Run as a service account with AD read permissions


---


This is the kind of automation that saves hours and makes you look like a hero to your team. More free scripts coming — follow this page.

Profile picture
qiao shengProfile picture@qiaoapplejuiceĀ·Apr 22
Pinned post

šŸ”§ Free Script: Bulk Check Which Servers Need a Reboot (Python)

If you manage Windows servers, you know the pain — after patches roll out, half of them need a reboot but nobody tracks which ones.


This script checks a list of servers and tells you exactly which ones have a pending reboot. Takes 5 seconds instead of RDPing into each one.


---


The Script


import subprocess
import sys

servers = [
    "SERVER-DC01",
    "SERVER-APP01", 
    "SERVER-FILE01",
    "SERVER-SQL01",
    "SERVER-WEB01",
    # Add your servers here
]

def check_pending_reboot(server):
    """Check if a Windows server has a pending reboot via registry key."""
    try:
        result = subprocess.run(
            ["reg", "query", f"\\\\{server}\\HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootPending"],
            capture_output=True, text=True, timeout=10
        )
        return result.returncode == 0
    except (subprocess.TimeoutExpired, Exception) as e:
        return None  # Unreachable or error

def main():
    print("=" * 50)
    print("  SERVER REBOOT CHECK")
    print("=" * 50)
    
    needs_reboot = []
    unreachable = []
    clean = []
    
    for server in servers:
        status = check_pending_reboot(server)
        if status is True:
            needs_reboot.append(server)
            print(f"  āš ļø  {server} — REBOOT PENDING")
        elif status is False:
            clean.append(server)
            print(f"  āœ…  {server} — Clean")
        else:
            unreachable.append(server)
            print(f"  āŒ  {server} — Unreachable")
    
    print("\n" + "=" * 50)
    print(f"  Summary: {len(needs_reboot)} need reboot | {len(clean)} clean | {len(unreachable)} unreachable")
    print("=" * 50)

if __name__ == "__main__":
    main()


---


How to use it


  1. Save as reboot_check.py

  2. Edit the servers list with your actual server names

  3. Run from any domain-joined machine: python reboot_check.py

  4. Requires network access to remote registry


---


What NexOps Pro members get


I drop scripts like this every week inside NexOps Pro — plus troubleshooting playbooks, AI prompts for IT tasks, and a members-only support chat.


Founding member spots are open at $5/mo (goes up to $19 after the first 20 members).


šŸ‘‰ Check it out if you want to stop doing repetitive IT work manually.