Powershell 仅在整个active directory下(一个OU除外)使用窗口7搜索广告计算机;残疾人士;

Powershell 仅在整个active directory下(一个OU除外)使用窗口7搜索广告计算机;残疾人士;,powershell,active-directory,powershell-4.0,Powershell,Active Directory,Powershell 4.0,我正在寻找脚本,以搜索只有Windows7电脑在广告中没有登录,因为60天。我正在使用此代码,但它不起作用: Import-Module ActiveDirectory $DaysInactive = 60 $time = (Get-Date).AddDays(-$DaysInactive) # Get all AD computers with lastLogonTimestamp less than our time Get-ADComputer -Filter { LastLogonTi

我正在寻找脚本,以搜索只有Windows7电脑在广告中没有登录,因为60天。我正在使用此代码,但它不起作用:

Import-Module ActiveDirectory
$DaysInactive = 60
$time = (Get-Date).AddDays(-$DaysInactive)

# Get all AD computers with lastLogonTimestamp less than our time
Get-ADComputer -Filter { LastLogonTimeStamp -lt $time -and OperatingSystem -like 'Windows 7 *'} -Properties LastLogonTimeStamp |
    Where-Object { $_.DistinguishedName -notlike '*,OU=COMPUTERS,OU=Quarantine,DC=ad,DC=int,DC=com,*' }

# Output hostname and lastLogonTimestamp into CSV
Select-Object Name, @{ Name = "Stamp"; Expression = { [DateTime]::FromFileTime($_.lastLogonTimestamp) } } |
    Export-Csv OLD_Computer.csv -NoTypeInformation

您只是缺少get和select之间的管道绑定,删除注释并替换为| like so:

Get-ADComputer -Filter { LastLogonTimeStamp -lt $time -and OperatingSystem -like 'Windows 7 *'} -Properties LastLogonTimeStamp | Where-Object { $_.DistinguishedName -notlike '*,OU=COMPUTERS,OU=Quarantine,DC=ad,DC=int,DC=com,*' } | Select-Object Name, @{ Name = "Stamp"; Expression = { [DateTime]::FromFileTime($_.lastLogonTimestamp) } } | Export-Csv OLD_Computer.csv -NoTypeInformation

这个命令在我的环境中执行得很好。

它到底是如何“不工作”的?您好,它没有给出所需的结果。我也不希望从隔离区1拾取系统。系统应为仅限Windows 7 2。60天内未登录3。排除检疫OU