How to obtain email of the logged in user in power

2019-04-21 04:47发布

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?

2条回答
仙女界的扛把子
2楼-- · 2019-04-21 05:15
PS> $searcher = [adsisearcher]"(samaccountname=$env:USERNAME)"
PS> $searcher.FindOne().Properties.mail
查看更多
虎瘦雄心在
3楼-- · 2019-04-21 05:29

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
查看更多
登录 后发表回答