powershell获取没有格式化的samaccountuser

时间:2014-01-27 17:48:34

标签: powershell active-directory

我写了一个powershell命令来返回samaccountname,我得到了我想要但不完全正确的东西。

PS C:\> (get-aduser -Server -f {(GivenName -eq "Nota") -and (Surname -eq "Realuser")} -Properties SamAccountName | select SamAccountName)

这就是我得到的:

SamAccountName

--------------
NRealuser

这就是我想要的:

NRealuser

所以我希望samaccountname没有标题。

1 个答案:

答案 0 :(得分:0)

您应该尝试ExpandProperty提供的Select-Object参数。

(Get-ADUser -Server -f {(GivenName -eq "Nota") -and (Surname -eq "Realuser")} -Properties SamAccountName | 
Select-Object -ExpandProperty SamAccountName)

你也可以跳过Select-Object部分,只是以“正常方式”检索属性的值,如下所示:

(Get-ADUser -Server -f {(GivenName -eq "Nota") -and (Surname -eq "Realuser")} -Properties SamAccountName).SamAccountName