> For the complete documentation index, see [llms.txt](https://aidenpearce369.gitbook.io/handbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aidenpearce369.gitbook.io/handbook/ad-pentesting/ad-enumeration/enumerating-log-on-and-log-off-activities.md).

# Enumerating Log On & Log Off Activities

### PowerView

Get username, last logged on, last log off of all users in current domain

```
Get-NetUser | Select samaccountname,lastlogon,lastlogoff
```

Get username, last logged on, last log off of a specific user in current domain

```
Get-NetUser -UserName <USERNAME> | Select samaccountname,lastlogon,lastlogoff
```

Get username, last logged on, last log off of all users in another domain

```
Get-NetUser -Domain <DOMAIN NAME> | Select samaccountname,lastlogon,lastlogoff
```

Get username, last logged on, last log off of a specific user in another domain

```
Get-NetUser -UserName <USERNAME> -Domain <DOMAIN NAME> | Select samaccountname,lastlogon,lastlogoff
```

Get "Last Logoff" property for all users in current domain

```
Get-UserProperty -Properties lastlogoff
```

Get "Last Logon" property for all users in current domain

```
Get-UserProperty -Properties lastlogon
```

Get "Last Logoff" property for all users in another domain

```
Get-UserProperty -Properties lastlogoff -Domain <DOMAIN NAME>
```

Get "Last Logon" property for all users in another domain

```
Get-UserProperty -Properties lastlogon -Domain <DOMAIN NAME>
```

Get actively logged users on a computer (needs Local Admin rights on target)

```
Get-NetLoggedon -ComputerName <SERVER NAME>
```

Get locally logged users on a computer (needs Remote Registry on target - started by default on Server OS)

```
Get-LoggedonLocal -ComputerName <SERVER NAME>
```

Get last logged user on a computer (need Local Admin right & Remote Registry on target)

```
Get-LastLoggedon -ComputerName <SERVER NAME>
```

Sort the last logged on time for all users in current domain

```
Get-NetUser | select samaccountname, lastlogon, pwdlastset | Sort-Object -Property lastlogon
```

Sort the last logged on time for all users on another domain

```
Get-NetUser -Domain <DOMAIN NAME> | select samaccountname, lastlogon, pwdlastset | Sort-Object -Property lastlogon
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aidenpearce369.gitbook.io/handbook/ad-pentesting/ad-enumeration/enumerating-log-on-and-log-off-activities.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
