简体   繁体   English

如何获取ADUER返回单个属性

[英]How To Get Get-ADUser To Return Individual Properties

I'm trying to clean up this code. 我正在尝试清理这段代码。 Isn't there a way to do something like this? 有没有办法做这样的事情?

$CurrentUserDetails = Get-ADuser -Identity $CurrentUserName -Properties *
$CurrentUserDetails.LastName (<-- This does not work.)

Instead of having to do this? 而不是必须这样做? (The below works) (以下作品)

$CurrentFirstName = (Get-ADuser -Identity $CurrentUserName -Properties GivenName).GivenName
$CurrentLastName = (Get-ADuser -Identity $CurrentUserName -Properties SurName).SurName
$CurrentDisplayName = (Get-ADuser -Identity $CurrentUserName -Properties DisplayName).DisplayName
$CurrentDistinguishedName = (Get-ADuser -Identity $CurrentUserName -Properties DistinguishedName).DistinguishedName
$CurrentUserPrincipalName = (Get-ADuser -Identity $CurrentUserName -Properties UserPrincipalName).UserPrincipalName

Any better? 好点?

$CurrentUserDetails = Get-ADuser -Identity $CurrentUserName -Properties *

$CurrentFirstName,
$CurrentLastName,
$CurrentDisplayName,
$CurrentDistinguishedName,
$CurrentUserPrincipalName =

$CurrentUserDetails.GivenName,
$CurrentUserDetails.Surname,
$CurrentUserDetails.DisplayName,
$CurrentUserDetails.DistinguishedName,
$CurrentUserDetails.UserPrincipalName
$name = Get-ADuser -Identity $CurrentUserName -Properties * | Select-Object 
Name,Created, LastLogon,GivenName,
SurName,DisplayName,DistinguishedName,UsserPrincipleName

This should give you all the objects you want to select 这应该为您提供要选择的所有对象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM