從about_ActiveDirecory_Filter
:
Filter Syntax
The following syntax descriptions use Backus-Naur form to show the
PowerShell Expression Language for the Filter parameter.
<filter> ::= "{" <FilterComponentList> "}"
<FilterComponentList> ::= <FilterComponent> |
<FilterComponent> <JoinOperator> <FilterComponent> |
<NotOperator> <FilterComponent>
<FilterComponent> ::= <attr> <FilterOperator> <value> |
"(" <FilterComponent> ")"
<FilterOperator> ::= "-eq" | "-le" | "-ge" | "-ne" | "-lt" | "-gt" |
"-approx" | "-bor" | "-band" | "-recursivematch" | "-like" |
"-notlike"
<JoinOperator> ::= "-and" | "-or"
<NotOperator> ::= "-not"
<attr> ::= <PropertyName> | <LDAPDisplayName of the attribute>
<value>::= < this value will be compared to the object data for
attribute <ATTR> using the specified filter operator
的Filter
參數轉換的PowerShell樣表達式的LDAP過濾器,但不支持只是任意PowerShell的說法,只有一組特定的比較操作與屬性名稱爲左邊的操作數和右邊的比較值。
做你Substring()
事先電話:
$substr = $computername.Substring(5,4)
Get-ADOrganizationalUnit -Filter {Name -like "$substr"}
方法調用,不支持作爲Active Directory過濾器內部的比較參數,造成PowerShell來忽略'(5,4)'一部分,並尋找一個叫做'屬性子串「 - 它不存在。在'Get-ADOrganizationalUnit'之前調用'Substring()'# –
試試:'Get-ADOrganizationalUnit -Filter {Name -like「* $($ computername.Substring(5,4))*」}' – arco444
感謝近作品 – Chester1111