PowerShell - 过滤器失败 - 不喜欢比较

PowerShell -Filters Failing on -notlike comparison

我有这个脚本试图从 AD 中拉出不活跃的用户,但如果有人没有标题,他们就不会被选中。我为单个用户测试了一个空标题的逻辑,它返回为 true,但是当它通过 foreach 运行时,它不起作用(输出显示只有具有标题的人是有效的)。我想也许 lastlogontimestamp 比较不起作用,所以我添加了 lastlogondate,但似乎标题仍然是问题,我不知道为什么?

#Inactivity Process

Import-Module ActiveDirectory 

# Gets time stamps for all User in the domain that have NOT logged in since after specified date. Exludes Prism and PlanLink providers.  
$DaysInactive = 365 
$time = (Get-Date).Adddays(-($DaysInactive))
$Out_file = "C:\scripts\adcleanup\Inactivity-365days-or-longer_$((Get-Date).ToString('MM-dd-yyyy')).csv"
$Out_file2 = "C:\scripts\adcleanup\FailInactivity-365days-or-longer_$((Get-Date).ToString('MM-dd-yyyy')).csv"

# Get all AD User with lastLogonTimestamp less than our time and set to enabled. Check All Users for this...
$Users = Get-ADUser -Filter {samaccountname -like "s0*" -and (enabled -eq $true) -and (Title -notlike "*PRISM*") -and (Title -notlike "*PlanLink*") } -Properties samaccountname,name,enabled,Title,LastLogontimestamp, lastlogondate |
select SamAccountname,Name,Title,@{Name="LastLogonTimeStamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}},lastlogondate, enabled 


Foreach ($User in $Users) {

    If (($user.LastLogontimestamp -le $time) -or ($user.LastLogondate -le $time))  {

        $User| export-csv $Out_file -notypeinformation -append

        }

    Else {

        $User | export-csv $Out_file2 -notypeinformation -append 

        }
        }

我想通了。

If (($user.LastLogontimestamp -le $time) -or ($user.LastLogondate -le $time) -or ($user.title -eq "") -and ($user.title -notlike "*PRISM*") -and ($User.title -notlike "*Planlink*") -and (!([string]::IsNullOrEmpty($user.lastlogondate)))) {