From 2bf6f0ba503c3bcb5a8c423c5af2f0ae7fc51268 Mon Sep 17 00:00:00 2001 From: Rephl3x Date: Wed, 24 Sep 2025 00:45:28 +0000 Subject: [PATCH] This script will read a CSV file with users in samaccountname format. Set the amount of Days in line 11 --- Ledger.ps1 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Ledger.ps1 diff --git a/Ledger.ps1 b/Ledger.ps1 new file mode 100644 index 0000000..286c287 --- /dev/null +++ b/Ledger.ps1 @@ -0,0 +1,29 @@ +#This script will read a CSV file with users in samaccountname format in a column named username and query AD for the last password set time based on the day count on line 11. + +# Define the path to the CSV file +$csvPath = "C:\temp\password-last-set.csv" # create a CSV file in a specific path with a column named username + +# Import the CSV file +$users = Import-Csv -Path $csvPath + +# Set the threshold in days +$thresholdDays = 0 + +# Calculate the threshold date +$thresholdDate = (Get-Date).AddDays(-$thresholdDays) + +# Iterate through each user in the CSV +foreach ($user in $users) { + # Get the SamAccountName from the CSV + $samAccountName = $user.username + + # Get the user object from Active Directory + $adUser = Get-ADUser -Filter { SamAccountName -eq $samAccountName } -Properties LastLogon + + # Check if the PasswordLastSet property exists and compare it with the threshold date + if ($null -eq $adUser.LastLogon) { + Write-Output "$samAccountName Password still unset" + } elseif ($adUser.LastLogon -lt $thresholdDate) { + Write-Output "$samAccountName Password was last set on $($adUser.PasswordLastSet)" + } +}