Skip to content

Instantly share code, notes, and snippets.

@pmbuko
Last active August 29, 2015 14:24
Show Gist options
  • Save pmbuko/132bfd7b45c806d84bab to your computer and use it in GitHub Desktop.
Save pmbuko/132bfd7b45c806d84bab to your computer and use it in GitHub Desktop.
This script should return the date and time of a logged in OS X user's Active Directory password expiration. Please test and let me know if you get an accurate value.
#!/bin/bash
USER=$(/usr/bin/python -c \
'from SystemConfiguration import SCDynamicStoreCopyConsoleUser;\
print SCDynamicStoreCopyConsoleUser(None, None, None)[0]')
xWin=$(/usr/bin/dscl localhost read /Search/Users/$USER \
msDS-UserPasswordExpiryTimeComputed 2>/dev/null |\
/usr/bin/awk '/dsAttrTypeNative/{print $NF}')
xUnix=$(echo "($xWin/10000000)-11644473600" | bc)
/bin/date -r $xUnix
@rderewianko
Copy link

  1. I added:
USER=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");'`

to get my username. When Run I get:
I get a error of:
(standard_in) 1: parse error
date: option requires an argument -- r
when I echo out both variables, they come back empty.

  1. OS: OSX 10.10.4
  2. DC: Win 2K8

@mrala
Copy link

mrala commented Jul 2, 2015

  1. Is the output of the script accurate?
    Yes
  2. What version of OS X are you running?
    10.10.4
  3. What version if Windows is/are your DCs running?
    2K12

I used the same method as rderewianko to define USER.

echo $expireDateWin
130849187704716095
❯ echo $expireDateUnix
1440445170
❯ date -r $expireDateUnix
Mon Aug 24 15:39:30 EDT 2015

@macmule
Copy link

macmule commented Jul 5, 2015

  • Is the output of the script accurate? Yes (well 28 seconds off of ADPassMon 2.10.1).
  • What version of OS X are you running? 10.9.5
  • What version if Windows is/are your DCs running? 2K8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment