Powershell Query AD - The Multifunctioning DBA

The Multifunctioning DBA

Jun 25 2009   6:12PM GMT

Powershell Query AD



Posted by: Colin Smith
Powershell, Active Directory

I have talked in the past about some cmdlets that Quest Software provides for Powershell. Well today they came in usefull for me. My boss came up and wanted to know when the last time a certain service account had authenticated to the domain. Now we log all users logging in via our login script but since this is a service account, the login script does not fire and therefore we do not get a log of the event. So using the cmdlets from Quest Software I did the following and got what we needed.

$1600users = Get-QADUser | where {$_.logonname -like “*p1600-10*”}
foreach($1600user in $1600users)
{
$name = $1600user
$date = $1600user.LastLogon
echo “$name logged in on $date”
}

That is it and it let us know that we have two accounts that have to do with the server services that we were interested in and also let us know the last logon time for each.

Hope this is helpful.

Comment on this Post


You must be logged-in to post a comment. Log-in/Register