Solved

Powershell / Quest cmdlets script that would get the lastlogon for all users in the domain

Posted on 2013-11-15
6
1,000 Views
Last Modified: 2013-11-26
Powershell / Quest cmdlets script that would get the lastlogon for all users in the domain.

This is what I have, but the lastlogon is incorrect because it does not query all of the Domain Controllers.  I would like someone to help me achieve this please.

get-qaduser –sizelimit 0 -IncludeAllProperties | select samaccountname,displayname,accountisdisabled,lastlogon,dn,parentcontainerdn,homemdb,msexchhomeservername | export-csv c:\UserStats_Report.csv -notype
0
Comment
Question by:mjm21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 39651549
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39651702
And if you want to use Quest commands then try..

$domain = "Domain.com" 
$myForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() 
$domaincontrollers = $myforest.Sites | % { $_.Servers } | Select Name 

Get-QADUser -SizeLimit 0 -dudip -Ip samaccountname,displayname,accountisdisabled,lastlogon,dn,parentcontainerdn,homemdb,msexchhomeservername | % {

$User = $_

$RealUserLastLogon = $null 
$domainsuffix = "*."+$domain 

foreach ($DomainController in $DomainControllers)  
{ 
    if ($DomainController.Name -like $domainsuffix ) 
    { 	Connect-QADService $DomainController.Name | Out-Null
        $UserLastlogon = (Get-QADUser $User.samaccountname -dudip -Ip lastlogon).lastlogon
        if ($RealUserLastLogon -le $UserLastlogon) 
        { 
            $RealUserLastLogon = $UserLastlogon
        }
    } 
}
	New-Object PSObject -Property @{
	samaccountname = $User.samaccountname
	displayname = $User.displayname
	accountisdisabled = $User.accountisdisabled
	lastlogon = $RealUserLastLogon
	dn = $User.dn
	parentcontainerdn = $User.parentcontainerdn
	homemdb = $User.homemdb
	msexchhomeservername = $User.msexchhomeservername
	}
} | select samaccountname,displayname,accountisdisabled,lastlogon,dn,parentcontainerdn,homemdb,msexchhomeservername
| Export-Csv C:\report.csv -nti

Open in new window

0
 

Author Comment

by:mjm21
ID: 39651809
Ok - this will check all domain controllers?
0
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

Author Comment

by:mjm21
ID: 39651822
Run and get this error:  

An empty pipe element is not allowed.
At line:34 char:1
0
 

Author Comment

by:mjm21
ID: 39651894
Ok - it is working now.
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39651990
There is a type.. You need to change the last lines to
} | select samaccountname,displayname,accountisdisabled,lastlogon,dn,parentcontainerdn,homemdb,msexchhomeservername |
Export-Csv C:\report.csv -nti

Open in new window

0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question