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