Powershell 获取当前用户samaccountname
# 获取当前用户的对象
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
# 提取用户名(去掉域前缀)
$userName = $currentUser.Name.Split('\')[-1]
# 获取当前用户的 sAMAccountName
$samAccountName = (Get-ADUser -Identity $userName -Properties sAMAccountName).sAMAccountName
# 输出 sAMAccountName
Write-Host "Current user's sAMAccountName: $samAccountName"
可以通过下面的命令查看用户的SAMAccountName是否存在于AD中:
Get-ADUser -Identity "Name" -Properties sAMAccountName
🏆 每日挑战:你知道答案吗?
如何在 Python 中检查变量的类型?
温馨提示 : 非特殊注明,否则均为©李联华的博客网原创文章,本站文章未经授权禁止任何形式转载;IP地址:52.14.49.59,归属地:俄亥俄州Dublin ,欢迎您的访问!
文章链接:https://www.lilianhua.com/powershell-retrieves-the-current-users-samaccount-name.html
文章链接:https://www.lilianhua.com/powershell-retrieves-the-current-users-samaccount-name.html