How to user where-object with a variable input

333 Views Asked by At

Ok so I am trying to use a variable to make up a where statement on a get-aduser command.

This is what I am trying to emulate which works:

get-aduser -filter * | where { $_.DistinguishedName -like "*Users,DC*" }
  • Note the are asterix before and after the User,DC. Not showing for some reason.

So here is what I have in the script which returns nothing:

$SearchBase = (get-addomain).DistinguishedName
$DefaultUsersOU = "*OU=Users," + $SearchBase

get-aduser -Filter * -Properties lastLogonTimeStamp -Searchbase "$($SearchBase)" | where-object { $_.DistinguishedName -like $DefaultUsersOU }

Found a similar article on here Where object as variable but if I apply that thinking to the DistinguishedName field it doesnt work either.

0

There are 0 best solutions below