Using "-Filter" with a variable in PowerShell -


i try filter out this:

get-adcomputer -filter {name -like "chalmw-dm*" -and enabled -eq "true" } .... 

this works charm , gets want...

now want "name -like .... " part variable this:

get-adcomputer -filter {name -like '$nameregex' -and enabled -eq "true" } | 

i checked several questions (for example, powershell ad module - variables in filter). isn't working me.

i tried following:

$nameregex = "chalmw-dm*" $nameregex = "`"chalmw-dm*`"" 

and in get-adcomputer command ' , without.

could give me hints?

you don't need quotes around variable, change this:

get-adcomputer -filter {name -like '$nameregex' -and enabled -eq "true" } 

into this:

get-adcomputer -filter {name -like $nameregex -and enabled -eq "true" } 

and ftr: you're using wildcard matching here (operator -like), not regular expressions (operator -match).


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -