How to get the Krbtgt last password set value using powershell

Hello,

For a script purpose I needed to have the date of the last password set of the Krbtgt account.
To do so I wrote this PowerShell function:

[ps]
Function Get-ADKrbtgtPwdLastSet{
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage=’Name of the domain.’,
Position=0)]
[ValidateScript({Test-Connection -ComputerName $_ -Count 2 -Quiet})]
[String]$DomainName = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().Name
)

Begin{
}
Process{
$RodcKrbtgtSearcher = [ADSISearcher]’serviceprincipalname=kadmin/changepw’
$RodcKrbtgtSearcher.SearchRoot = "LDAP://$DomainName"
$RodcKrbtgtSearcher.FindAll() | Foreach-Object -Process {
New-Object -TypeName PSObject -Property @{
UserID = [String]$_.properties.samaccountname
PasswordLastSet = [datetime]::FromFileTime([String]$_.properties.pwdlastset)
}
}
}
End{
}
}
[/ps]