gpt4 book ai didi

powershell - 在PowerShell中的foreach内部使用变量的字段

转载 作者:行者123 更新时间:2023-12-02 23:10:34 27 4
gpt4 key购买 nike

因此,我有一个Active Directory用户列表:

$users = Get-AdUser -Filter {Enabled -eq "True"}

我要根据他们的描述将它们分组,因为您在整个用户列表中有3种可能的描述。

但是:我什至似乎都没有在 Description内使用 foreach字段:
foreach ($user in $users)
{
Write-Host $user.Name
Write-Host $user.Description
}

它们的名称显示但不描述。

为什么是这样?

最佳答案

Get-ADUser默认仅返回特定属性。 description属性不是其中之一。为了确保返回,您需要在Get-ADUser中使用以下参数:
-Properties Description

"This cmdlet retrieves a default set of user object properties. To retrieve additional properties use the Properties parameter." - https://technet.microsoft.com/en-gb/library/ee617241.aspx

关于powershell - 在PowerShell中的foreach内部使用变量的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43271997/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com