Your logic isn’t identical in the script and manual steps
script:
InactiveCount=@($members|?{$_.lockedout -or $_.Enabled -eq $false}).count
manual:
$i=($m|?{$_.lockedout -or $_.enabled -like ‘false’}).count
As an aside don’t use aliases for cmdlets and parameters in scripts. if a puppy is killed every time you use write-host you don’t want to see what happens when aliases are used in scripts.
You don’t need to use -property * on Get-ADuser you can list the extra properties you need. It’ll cut down the data returned.
In this line
InactiveCount=@($members|?{$_.lockedout -or $_.Enabled -eq $false}).count
why do you need the @
$members is already an array and you are just filtering the members
The errors are probably due to AD not understanding what you are trying to do. Piping the output of get-adgroupmember into get-aduser should work