Mark Minasi's Tech Forum
Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
meloao

New Friend (or an Old Friend who Built a New Account)
Registered:
Posts: 98
Reply with quote  #1 
I have some code that gets the pwdLastSet attribute.  $userPwdSetTime is in the format mm/dd/yyyy hh:mm.  I would like for it to return True if the current date - $userPwdSetTime is more than 45 days, otherwise return False if the current date $userPwdSetTime is less than 45 day.

$userSAM = Get-ADUser -Identity $user -Properties pwdLastSet

$userPwdOutput = $UserSAM.pwdLastSet
$userPwdSetTime = [datetime]::FromFileTime($usersam.pwdLastSet)

 

0
cj_berlin

Avatar / Picture

Senior Member
Registered:
Posts: 377
Reply with quote  #2 
Hi,

that's the beauty of real [datetime] values as opposed to textual representations:


(New-TimeSpan -Start $userPwdSetTime).TotalDays -gt 45


Enjoy [smile]

__________________
Evgenij Smirnov

My personal blog (German): http://www.it-pro-berlin.de/
My stuff on PSGallery: https://www.powershellgallery.com/profiles/it-pro-berlin.de/
0
meloao

New Friend (or an Old Friend who Built a New Account)
Registered:
Posts: 98
Reply with quote  #3 
Wow, learned something new about [datetime].  Also, the New-Timespan command is new for me so I will have to look into that as well.

Thanks again!
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.