How to obtain email of the logged in user in powershell

白昼怎懂夜的黑 提交于 2020-01-13 08:07:12

问题


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?


回答1:


PS> $searcher = [adsisearcher]"(samaccountname=$env:USERNAME)"
PS> $searcher.FindOne().Properties.mail



回答2:


I'd be concerned that the given answer doesn't use the fully qualified name. Granted that won't be a problem in most cases, but the method I'm using is as follows:

([adsi]"LDAP://$(whoami /fqdn)").mail


来源:https://stackoverflow.com/questions/8666627/how-to-obtain-email-of-the-logged-in-user-in-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!