由于 Win32 FileTime 无效,Powershell Get-ADUser 对于日期属性失败

问题描述 投票:0回答:1

以下 powershell 命令适用于大多数帐户。

import-module activedirectory
Get-ADUser <account> -Properties *

对于某些帐户,我收到以下错误

Get-ADUser : Not a valid Win32 FileTime.
Parameter name: fileTime
At line:4 char:1
+ Get-ADUser <account> -Properties AccountExpirationDate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (<account>:ADUser) [Get-ADUser], ArgumentOutOfRangeException
    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentOutOfRangeException,Microsoft.ActiveDirectory.Management.Commands.GetADUser

我怀疑这是因为空(?)日期属性。

对于有效帐户,它看起来像这样

AccountExpirationDate : 01/01/2030 00:00:00

有没有办法仍然收集这些用户的信息,只是排除日期属性?

由于有数百个属性,我宁愿避免指定我需要的属性......除非它不会对性能产生影响?

我尝试了下面的操作,可能是由于选择失败的查询而失败。

Get-ADUser <account> -Properties * | Select-Object -Property * | Where-Object { $_.AccountExpirationDate -ne $null}
powershell active-directory get-aduser
1个回答
0
投票

检查

accountExpires
LDAP 属性是否从未设置过(值 0),或者用户的属性是否已设置为“永不过期”(值 9223372036854775807)
在这两种情况下,您需要的
AccountExpirationDate
属性中都不会存在有效的日期时间。

此外,如果您只需要在 Get-ADUser 默认返回的属性之上添加一些额外属性,则不应使用

-Properties *
,这些属性是:
DistinguishedName、Enabled、GivenName、Name、ObjectClass、ObjectGUID、SamAccountName、SID、Surname、UserPrincipalName

尝试

Get-ADUser -Filter 'Enabled -eq $true' -Properties AccountExpirationDate, accountExpires |
Where-Object { $_.accountExpires -gt 0 -and $_.accountExpires -ne 9223372036854775807 } |  # exclude users with account Never Expires
Select-Object Name, SamAccountName, AccountExpirationDate | 
Sort-Object AccountExpirationDate -Descending
© www.soinside.com 2019 - 2024. All rights reserved.