Help in my Script

Hello,

First of all, sorry for my english! I am a beginer in the world of the powershell and i want to learn things. I am stuck for a 5 hours now.

So i want to creat a script on a Windows Server that can tell me who’s password gonna expire in the next 30 days.

When we reach 30 days before the password of the user expire, i want to get notified by an email or SMS ( i already got the material to send SMS).

In order to do this, i started to creat something :

$date = Get-Date
$fichier = "C:\Users\username\Documents\fichier.txt"
$Listusers = Get-ADUser -Filter * -SearchBase "OU=Test,DC=domain,DC=local"

# Creat or update the file $fichier="C:\Users\username\Documents"
Set-Location "C:\Users\username\Documents"
Remove-Item $fichier -Force

# Add the date to the file
New-Item -Name "fichier.txt" -ItemType file -Value "$date"

# Retrive date of user's password
Get-ADUser -Filter * -SearchBase "OU=Test,DC=domain,DC=local" –Properties "DisplayName", "msDS-UserPasswordExpiryTimeComputed" | Select-Object -Property "Displayname",@{Name="ExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}

When i execute this, no error and everything goes well, but i dont know how to proceed next, everything that i found dont fit what i am searching for.

 

Hope someone could help me.

Hi Noka40

This will help you to get 30 days in the future

[pre]

(get-date).AddDays(30)

[/pre]

You can use this to check your returned date to see if it will expire

So for every users returned check this with an foreach check

I encourage you to continue learning the shell, but this is something already solved :slight_smile:

https://gallery.technet.microsoft.com/scriptcenter/Password-Expiry-Email-177c3e27

Hello,

 

Thank you Bart, this will help me!

Thank you David for the link, this will help me too in my script, i will inspire me from this one!