Again we have to loop through the domain controllers but we don’t get a cmdlet for that. There’s a nice easy bit of .NET we can use
function Get-QADUserLastLogon{ param( [string]$userName ) [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() | select -ExpandProperty DomainControllers | foreach { $dc = $_.Name $null = Connect-QADService -Service $dc Get-QADUser -Identity $userName | select Name, LastLogon, @{N="Domain Controller"; E={$dc}} Disconnect-QADService } } Get-QADUserLastLogon -UserName Richard
We need to use Connect-QADService to connect to a specific domain controller and the LastLogon attribute is translated to a readable format for us
Last job is to disconnect
Advertisement