我想獲取某個用戶所屬的所有組,然后按某個名稱過濾組,然后顯示這些組的屬性“描述”。
我使用此命令獲取用戶組
$mem = ( Get-AdUser someLogin -Properties MemberOf ).MemberOf
現在我可以使用此命令獲取所有這些組的描述 - 這很好用:
$mem | Get-AdGroup -Properties Description | Select-Object Name, Description
name description
---- ------------
group100 descr. 100
group222 descr 222
....
group999 descr. 999
我想要的是只顯示一些包含一些字串的組,比如說“888”。
我嘗試了下面的命令,但有一個我不明白的錯誤:
$mem | Select-String '888' | Get-AdGroup -Properties Description | Select-Object Name, Description
Get-AdGroup : The input object cannot be bound to any parameters for the command either because the command
does not take pipeline input or the input and its properties do not match any of the parameters
that take pipepline input.
uj5u.com熱心網友回復:
這應該作業
$mem | Select-String '888' | Select-Object -ExpandProperty Line | Get-ADGroup -Properties Description | Select-Object Name, Description
Select-String 的輸出是一個Microsoft.PowerShell.Commands.MatchInfo-objects陣列,因此為了讓您能夠實際獲得 AD 組,您需要使用實際匹配的行擴展屬性 ( Line)。您可以運行($mem | select-string '888')[0] | select *以進一步檢查物件。
另一種可能更常見的方法是利用Where-Object- 例如
$mem | Where-Object { $_ -like "*888*" } | Get-ADGroup -Properties Description | Select-Object Name, Description
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/376423.html
標籤:电源外壳
