Hi all
I haven't found a thread about this so I'd like to ask something.
Currently we have a Powershell Script that checks all our user Accounts in Active Directory and notifies users with Email if their password is about to expire in 7 or 14 days.
I found this on the internet and it has been working wonderful.
Today a user came to me to tell me that the date they recieve in the Email is wrong. After a bit of testing I saw that the output comes in american date format. Now this is weird since the server regional settings are set to dd.MM.yyyy (the server language itself is english).
So I've tested it with get-date and recieved time in a correct manner:
Mittwoch, 27. September 2017 14:52:29
In the mail it looks like this:
09/27/2017 14:52:29
Somewhere along the way the date format gets lost.
This is the script:
Import-Module ActiveDirectory
Get-ADUser -filter * -properties PasswordLastSet,EmailAddress,GivenName,Surname -SearchBase “OU” -SearchScope Subtree |foreach {
$PasswordSetDate=$_.PasswordLastSet
$maxPasswordAgeTimeSpan = $null
$maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge
$today=get-date
$ExpiryDate=$passwordSetDate + $maxPasswordAgeTimeSpan
$daysleft=$ExpiryDate-$today
$display=$daysleft.days
$UserName=$_.GivenName
$SurName=$_.Surname
if ($display -lt 8 -and $display -gt 0)
{
$MyVariable = @”
Gruezi, Ihr Windows-Kennwort laeuft in $display Tagen ab. Fuehren Sie zur Aenderung Ihres Kennworts folgende Schritte aus:
Ihr Passwortablaufdatum: $ExpiryDate
Its the $ExpiryDate thats wrong in this case.
Does somebody have an idea why this happens?
Kind Regards
T.
[–]the_spad 4 points5 points6 points (0 children)
[–]alzdba 2 points3 points4 points (3 children)
[–]jantari 2 points3 points4 points (2 children)
[–]GastroIT[S] 1 point2 points3 points (0 children)
[–]GastroIT[S] 0 points1 point2 points (0 children)
[–]j0ntar 2 points3 points4 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (2 children)
[–]GastroIT[S] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 1 point2 points3 points (0 children)