Lephas
Lephas

Reputation: 25

Powershell Filter ADgroups the right way

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?

Upvotes: 0

Views: 61

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 175085

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}*'"

Upvotes: 2

Related Questions