SynopsisGets the users currently logged on interactively to a local or remote computer.
- Get-CurrentUser [-ComputerName] [-Credential]
- Get-CurrentUser [-ComputerName] [-Console] [-Credential]
- Get-CurrentUser [-ComputerName] [-Remote] [-Credential]
DescriptionThe Get-CurrentUser cmdlet returns information about the users currently logged on to a computer in an interactive session (desktop and remote desktop users, but not service accounts or users attached to a network share). The logon sessions returned will have one of three logon types: Console, where the user is logged on at the computer; Remote, where the user is logged on via Remote Desktop or Terminal Services; Console Cached, where the user is logged on at the computer, but with a cached domain account.
- ComputerName The computer against which to run the cmdlet. By default this parameter will be populated with the name of the local computer.
- Console Return the user that is logged in to the console of the computer only.
- Remote Return users that are logged in via Remote Desktop or Terminal Services connections to the computer only.
- Credential The credentials under which to run the cmdlet. By default this cmdlet will run as the current user. Using this parameter and the Get-PSCredential cmdlet you can specify an alternate set of credentials under which to execute this command.
InputsGet-CurrentUser accepts pipeline input only for the ComputerName parameter and requires that the input object contain a property named either Computer, CN or ComputerName.
OutputsGet-CurrentUser outputs a Vexasoft.LogonSession object detailing the interactive desktop sessions in use on the specified computer.
NotesThe Get-CurrentUser cmdlet requires that the RPC service is started on the computer it is trying to access and that DNS services are available to resolve target host names. Additionally, administrator rights are required in some configurations to retrieve logon type and logon time information.
Example 1This command will retrieve the current users of the local computer:
Example 2This command will the current users of the remote computer PC01:
C:\PS>Get-CurrentUser -Computer PC01
Example 3This command will retrieve the console user of the remote computer PC01 only, ignoring any Remote Desktop or Terminal Services connections:
C:\PS>Get-CurrentUser -Computer PC01 -Console