我正在尝试编写一个 Powershell 脚本来识别 90 天未登录的用户,但我不断收到此错误消息:
找不到“op_Subtraction”的重载和参数计数:“2”。起初我认为这是一个变量类型不匹配,但查看变量进行减法它看起来不错。
PS C:\> $today.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True DateTime System.ValueType
PS C:\> $users[198].LastLogonDate.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True DateTime System.ValueType
$today = Get-Date
$days = 90
$users = Get-ADUser -Properties * -Filter *
foreach ($i in $users)
{
$difference = $today - $i.LastLogonDate
#Write-Host $i.Name + $difference.Days
if ($difference.Days -ge $days){Write-Host $i.name " hasn't logged on in 90 days"}
elseif ($i.LastLogonDate -eq $null) {Write-Host $i.name " has null value"}
else {Write-Host " No Value"}
}
想法??
谢谢!!