Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain email of the logged in user in powershell

Using Vbscript , we are getting current user email id. It is as simple as with following lines.

Option Explicit

Dim objUser, objADSysInfo

Set objADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
WScript.Echo objUser.Mail

How to achieve the same using powershell?

like image 999
Samselvaprabu Avatar asked Dec 29 '11 10:12

Samselvaprabu


People also ask

Which user is logged in PowerShell?

Use the query Command to Get Logged on Users in PowerShell Windows has a built-in command-line tool called the query command to list all the currently logged-on users on a computer. The command also shows us if the user logged on via a remote desktop session or locally to the computer.


1 Answers

PS> $searcher = [adsisearcher]"(samaccountname=$env:USERNAME)"
PS> $searcher.FindOne().Properties.mail
like image 150
Shay Levy Avatar answered Oct 12 '22 03:10

Shay Levy