gpt4 book ai didi

POWERSHELL - 调用运算符(operator) - 这个结构是什么意思?

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

这段代码运行良好。它是从微软复制的。

$strFilter = "(&(objectCategory=person)(objectClass=user))" 

$objDomain = New-Object System.DirectoryServices.DirectoryEntry

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter

$colProplist ="Name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

$colResults = $objSearcher.FindAll()

foreach ($objResult in $colResults)
{$objItem = $objResult.Properties; $objItem.name }

但是,我不明白为什么老师使用
 $strFilter = "(&(objectCategory=person)(objectClass=user))" 

因为我从网上获得的所有信息都是这个符号 & 用于执行代码,一旦它的意思是“调用运算符(operator)”。

我认为,在这种情况下,它具有其他含义。

最佳答案

复合搜索/过滤表达式

(&(objectCategory=person)(objectClass=user))

等效于编程语言上下文中的以下条件:
objectCategory == person && objectClass == user

它记录在 MSDN page for DirectorySearcher.Filter Property :

Compound expressions are formed with the prefix operators & and |. An example is "(&(objectClass=user)(lastName= Davis))". Another example is "(&(objectClass=printer)(|(building=42)(building=43)))".



因此,过滤器应用为:
objectClass=user && lastName= Davis


objectClass=printer && ( building=42 || building=43)

分别在提供的片段中。

关于POWERSHELL - 调用运算符(operator) - 这个结构是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33391335/

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