Powershell <= v2 Get-在过去两个月内通过身份验证的计算机

Powershell <= v2 Get-Computer that authenticated in the last two months

计算机需要不再受支持(已涵盖),但还需要在过去两个月内通过域进行身份验证。我找到了 Get-Date 函数,但是 v5 支持它,我最多需要 v2.

Get-ADComputer `
-Filter {(OperatingSystemVersion -le "5.2") -or (OperatingSystemVersion -notlike "*")} `
-Properties *

我找到了一篇关于 2010 年的 Get-Date 的博文,所以它不可能是 v5。如果我查看 technet,它会显示 v5。现在我不确定它支持哪个版本。

我希望以下内容会起作用 ((LastLogonDate) -ge ((Get-Date).AddDays(-60)))

只使用 .net 怎么样?

您也可以通过将上面的内容包装在一个函数中来自己滚动

Function get-date {
[cmdletbinding()]
Param([Parameter(mandatory = $false)][string]$inputobject)
    if ($inputobject) { [datetime]:: parse($inputobject) }
    else {  [datetime]::now }
}

由于 PS2 不支持自动注册,这应该可以正常工作:

$refdate = Get-Date
$refdate = $refdate.adddays(-60)
Get-ADComputer `
-Filter {((OperatingSystemVersion -le "5.2") -or (OperatingSystemVersion -notlike "*")) -and (lastlogondate -ge $refdate)} `
-Properties *

自动注册 - 在 powershell 3 中引入 - 允许您使用括号内的对象来使用其方法和属性。在 powershell 3 中,你可以通过 (Get-date).AddDays(-60) 并使用它的输出。