Last Logon time with Quest cmdlets

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
This entry was posted in PowerShell and Active Directory. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s