$computername = 'RSERV1234'
$computername.Substring(5,4) returns '1234' as expected
Get-ADOrganizationalUnit -Filter {Name -like $computername.Substring(5,4)}
返回:
Property 'Substring' not found in object of type: 'System.String'
请帮忙!
答案 0 :(得分:0)
来自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"}