function Get-ADUserLastLogon($userName) { $dcs = Get-ADDomainController -Filter {Name -like "*"} $time = 0 foreach($dc in $dcs) { $hostname = $dc.HostName $user = Get-ADUser $userName -Server $hostname | Get-ADObject -Properties lastLogon if($user.LastLogon -gt $time) { $time = $user.LastLogon } } $dt = [DateTime]::FromFileTime($time) Write-Host $username.samaccountname "last logged on at:" $dt } $Groups = Get-ADGroup -Filter {Name -like "fi*"} $groupmembers = @() ForEach ($Group in $Groups) { $groupmembers += (Get-ADGroupMember -Identity "$($Group.Name)" -Recursive) } $groupmembers = $groupmembers|select -Unique foreach($account in $groupmembers) { Get-ADUserLastLogon -UserName $account }