问题
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