From 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
The Filter parameter translates PowerShell-like expressions to an LDAP filter, but doesn't support just any arbitrary PowerShell statement, only a specific set of comparison operations with attribute names as the left-hand operand and the comparison value on the right hand side.
Do your Substring() call beforehand:
$substr = $computername.Substring(5,4)
Get-ADOrganizationalUnit -Filter {Name -like "$substr"}
(5,4)part and look for a property calledSubstring- which doesn't exist. CallSubstring()beforeGet-ADOrganizationalUnitGet-ADOrganizationalUnit -Filter {Name -like "*$($computername.Substring(5,4))*"}