Hello Misyw,
This is because before the -notlike there is not a defined property, thus can't exclude something from a null reference.
You will need to define first the property as membership, then specify the ones no in the group. Like this:
-properties memberof | Where-Object {!($_.memberof -like "ExcludeGroup")}
You can test this with a count of users, for example:
Get-ADUser -Filter * -properties memberof | Where-Object {!($_.memberof -like "permanent")} | measure
--If the reply is helpful, please Upvote and Accept as answer--