简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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