Wednesday, July 9, 2008

A few more days left to take advantage of TechEd Asia 2008's promotions

Wanna save money for your TechEd Asia 2008 registration? Register on or before July 15, 2008 and pay only RM 999 (US$323). Compare that to RM 1,299 (US$419) which is the regular price. What's more, if you register in a group of 5 or more, you save an additional RM 100 (US$33). You only pay RM 899 (US$291). So hurry because you only have a few days left before the 15th. For more details, check out the TechEd Asia 2008 site

Tuesday, July 8, 2008

Extract user's last password set in Active Directory using PowerShell

Just a follow up on my previous post, here's the script to do just that in PowerShell. It extracts the name and the last time the password was changed and displays it in the host.

$strFilter = "(&(objectCategory=User))"
$Dom = 'LDAP://DC=yourDomain;DC=LOCAL'

$objDomain = New-Object System.DirectoryServices.DirectoryEntry $Dom

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"

$colProplist = "name", "pwdlastset"
foreach ($i in $colPropList)
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
$objItem = $objResult.Properties

One-liner in PowerShell? Convert a 64-bit (Integer8) value to date time

As I was converting my VBScripts to PowerShell, I reviewed one which checks for the password expiration of a user in Active Directory. The blog post I've had sometime last year extracts object properties and one of them is the pwdLastSet property which specifies a 64-bit value of when the user last changed their passwords. This is necessary if you need to know how many days left before their password expires. One of the things I did was to use a function that converts the 64-bit value to a valid date/time value - thanks to Richard Mueller, of course.

Function Integer8Date(ByVal objDate, ByVal lngBias)
' Function to convert Integer8 (64-bit) value to a date, adjusted for
' local time zone bias.
Dim lngAdjust, lngDate, lngHigh,
' Account for bug in IADslargeInteger property methods.
If (lngLow < 0)
lngHigh = lngHigh +
End If

(lngHigh = 0) And (lngLow = 0)
lngAdjust =
End If

lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32))
+ lngLow) / 600000000 - lngAdjust) /

= CDate(lngDate
End Function

I pass the value from pwdLastSet property to this function to get the date/time value. After a couple of Google searches, I chanced upon a forum post by Brandon Shell - Microsoft PowerShell MVP. The entire function can be summed up in just a line


This is if you are using the System.DirectoryServices.DirectorySearcher class and not the
System.DirectoryServices.DirectoryEntry in the .NET Framework which is available in PowerShell. The DateTime.FromFileTimeUtc Method converts the specified Windows file time to an equivalent UTC time. So much for using conversion functions in VBScript to do this.