0

Hi im trying to Filter AD-Groups by a string i defined in a variable:

$groupname="string" Get-ADGroup -filter {GroupCategory -eq "security" -and Name -like ($sgroup_name+"*")} 

How do i do this the right way?

0

1 Answer 1

2

String expansion doesn't work well with the -Filter parameter when passing it a script block - use a string filter instead:

$groupname = "string" Get-ADGroup -Filter "GroupCategory -eq 'security' -and Name -like '${groupname}*'" 
Sign up to request clarification or add additional context in comments.

1 Comment

I know you just copied what the op had but the code should work as intended now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.