Powershell - Syntax error - pasting string from a function into "-Filter" -
here code: try build filter string in function , in , get-adobject command, syntax error position 1
function build-filter ([string]$searchname) { $searchname = '"' + $searchname + '"' $searchname = "{name -like " + $searchname + "}" return [string]$searchname } $searchname = "user1" $filter = build-filter $searchname get-adobject -filter $filter
this error message, unfortunatelly in german
get-adobject : fehler beim analysieren der abfrage: "{name -like "user1"}" fehlermeldung: "syntax error" folgender position: "1". in zeile:12 zeichen:1 + get-adobject -filter $filter + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : parsererror: (:) [get-adobject], adfilterparsingexception + fullyqualifiederrorid : activedirectorycmdlet:microsoft.activedirectory.management.adfilterparsingex ception,microsoft.activedirectory.management.commands.getadobject
what doing wrong here? missunderstand concept?
try changing this:
$searchname = "{name -like " + $searchname + "}"
in
$searchname = "name -like $searchname"
Comments
Post a Comment