Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Last logon active directory

$
0
0

Best,

I want to see the last logon of all users in our AD (win2k8). but im such a noob in scripting etc. I just found this script on here what does it do?
i want to have a script that lets see the username, last logon time and it has to be saved as an .csv file or something like it.
the users in the AD are in different user OU's is it possible to get them all at once?

The users are settled in icl-ips (local) > zICL ip HD > IPT > Users
below this ou are 7/8  containers with users.

Can somebody help pls thank you,

Regards,
kevin

Ps. this is the script i found

$user = $args[0]
$domain = $args[1]
 
$domain = $domain.tolower()
 
#Suppress Errors for DC's that have computer accounts but not connected to the domain
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::SilentlyContinue
$WarningPreference = [System.Management.Automation.ActionPreference]::SilentlyContinue
 
Switch($domain)
{
    domain1 {$dom = "icl-ips.com"}
}
 
Connect-QADService -service $dom
 
Get-QADComputer -ComputerRole DomainController -activity "Compiling Domain Controllers in $Domain" | % {
$dc = $_.Name
Get-QADUser -service $dc -samaccountname $User } | sort-object lastLogon -descending | select-object name, lastlogon -first 1

 


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>