Support
 
Phone Get Quote
 
Support
 
US: +1 888 720 9500
US: +1 888 791 1189
Intl: +1 925 924 9500
Aus: +1 800 631 268
UK: 0800 028 6590
CN: +86 400 660 8680

Direct Inward Dialing: +1 408 916 9892

How to get users logged on to remote computer

The following is a comparison between the procedures for identifying users logged on to remote computer using Windows PowerShell and ADAudit Plus:

PowerShell

Steps to obtain users logged on to a remote computer using PowerShell:

  • Identify the domain from which you want to retrieve the report.
  • Identify the LDAP attributes you need to fetch the report.
  • Identify the primary DC to generate the report.
  • Compile the script.
  • Execute it in Windows PowerShell
  • The report will be exported in the format specified in the script.
  • To obtain the report in a different format, modify the script according to the needs of the user.

Sample Windows PowerShell script

Import-Module ActiveDirectory
 
Get-RDUserSession -ConnectionBroker connection-broker-name
{
$dcs = Get-ADDomainController -Filter {Name -like "*"}
$users = Get-ADUser -LDAPFilter "(&(objectCategory=person)(objectClass=user))"
$time = 0
$exportFilePath = "c:\scripts\lastLogon.csv"
$columns = "name,username,datetime"
Out-File -filepath $exportFilePath -force -InputObject $columns
foreach($user in $users)
{
foreach($dc in $dcs)
{ 
$hostname = $dc.HostName
$currentUser = Get-ADUser $user.SamAccountName | Get-ADObject -Server $hostname -Properties lastLogon
if($currentUser.LastLogon -gt $time) 
{
$time = $currentUser.LastLogon
}
}
if($time -eq 0){
$row = $user.Name+","+$user.SamAccountName+",Never"
}
else {
$dt = [DateTime]::FromFileTime($time)
$row = $user.Name+","+$user.SamAccountName+","+$dt
}
Out-File -filepath $exportFilePath -append -noclobber -InputObject $row
$time = 0
}
}
 Copied
Click to copy entire script

ADAudit Plus

To obtain the report,

  • Reports -> Local Logon-Logoff -> Currently Logged On Users
  • Select the required 'Domain'.
  • Select 'Export as' to export the report in any of the preferred formats (CSV, PDF, HTML, and XLS).

Screenshot

get-remote-logged-on-user-with-powershell-1
 

Following are the limitations in obtaining every user logged on to remote computers using native tools like Windows PowerShell:

  • We can run this script only from the computers which has Active Directory Domain Services role.
  • Difficult to change date formats.
  • Difficult to apply different time zones on the date results.
  • Difficulty in exporting the report in other formats.
  • Applying more filters, like 'During business hours' will increase the LDAP query complexity.

ADAudit Plus will automatically scan all DCs in the domain to retrieve information about the users currently logged on remotely to a computer, generate the report and present it in a simple and intuitively designed UI.

  • Avoid complex PowerShell-scripting, and simplify AD change auditing with ADAudit Plus.
  • Avoid complex PowerShell-scripting, and simplify AD change auditing with ADAudit Plus.
  •  
  • By clicking 'Get Your Free Trial', you agree to processing of personal data according to the Privacy Policy.
  •  
  • Thanks!
  • Your download is in progress and it will be completed in just a few seconds! If you face any issues, download manually here.

Related Resources

ADAudit Plus Trusted By