我正在尝试清理此代码。有没有办法做这样的事情?
$CurrentUserDetails = Get-ADuser -Identity $CurrentUserName -Properties *
$CurrentUserDetails.LastName (<-- This does not work.)
而不是必须这样做? (以下作品)
$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
答案 0 :(得分:2)
还好吗?
$CurrentUserDetails = Get-ADuser -Identity $CurrentUserName -Properties *
$CurrentFirstName,
$CurrentLastName,
$CurrentDisplayName,
$CurrentDistinguishedName,
$CurrentUserPrincipalName =
$CurrentUserDetails.GivenName,
$CurrentUserDetails.Surname,
$CurrentUserDetails.DisplayName,
$CurrentUserDetails.DistinguishedName,
$CurrentUserDetails.UserPrincipalName
答案 1 :(得分:0)
$name = Get-ADuser -Identity $CurrentUserName -Properties * | Select-Object
Name,Created, LastLogon,GivenName,
SurName,DisplayName,DistinguishedName,UsserPrincipleName
这应该为您提供要选择的所有对象