什么是dsCorePropagation属性,为什么我的脚本使用它?

问题描述:

因此,我有一个脚本,用于在两种情况下查询LastLogonTimeStamp属性和删除帐户,其中一个是属于两个安全组,另一个是他们在75天内没有登录到计算机。下面是我的脚本:什么是dsCorePropagation属性,为什么我的脚本使用它?

$75DayExemptGroup = Get-ADGroup -Identity "AccountComplianceExemption_75DayLimit" | Select -exp DistinguishedName 
$AccountInactvityGroupMembers = Get-ADGroup -Identity "AccountComplianceExemption_AccountInactivity" -Properties Members | Select -ExpandProperty Members 

foreach ($UserDN in $AccountInactvityGroupMembers) { 
$fullADUser = Get-ADUser $UserDN -properties LastLogonTimeStamp,MemberOf,Description,CanonicalName -ErrorAction SilentlyContinue | Where {$_.DistinguishedName -notlike "*MAB_Devices*" -and $_.DistinguishedName -notlike "*Mailboxes*" -and $_.DistinguishedName -notlike "*AFG TNOSC*" -and $_.Name -notlike "svc.*" -and $_.Name -notlike "grp.*"} 
if ($fullADUser.MemberOf -like "*$75DayExemptGroup*") { 
    $LastLogonDate = [DateTime]::FromFileTime($fullADUser.LastLogonTimeStamp) 
    $75Days = [datetime]::Today.AddDays(-75) 
    if ($LastLogonDate -lt $75Days -and $fullADUser.LastLogonTimeStamp -ne $null) 
    { 
     $OrigDesc = $fullADuser.Description 
     $OUPath = $fullADuser.CanonicalName 
     $NewDesc = "Deleted by JNCC-A for 75 days of inactivity - Original Desc [$OrigDesc] - OU: $OUPath" 
     Set-ADUser $fullADuser -Description $NewDesc 
     if ($?) {Remove-ADUser $fullADUser -Confirm $false} 
    } 
    $LastLogonDate = "" 
    } 
} 

所以我运行脚本,对吧?有两个用户在两个组中,对吗?然后有一个用户低于75天标记,一个高于75天标记,然后是一个从未登录过的用户,因此在AD对象中显示“<not set>”。现在,当我的脚本比较用户的$ LastLogonDate变量从未登录时,它显示日期“1601 1月1日4:30:00 AM”。现在,我认为这是某种默认情况下,当值为null或0我猜,但我仔细观察了ADUC对象,并在“dsCorePropagation”属性中显示该日期,当我在Powershell中查询它时,它显示日期,但是当我查看AD对象上的该属性时,它包含“0”的十六进制代码。

我的脚本按照原样运行,因为我将$ fullADUser.LastLogonTimeStamp与null比较,我只是认为获取更多视角会更有趣,因为$ LastLogonDate变量不为null,因为$ fullADUser.LastLogonTimeStamp为null。

由于System.DateTime的是一个非空类型,因此,如果您通过FromFileTime空或零值,它只会返回最小FILETIME值,这是1601年1月1日

C:\WINDOWS\system32> [datetime]::FromFileTime($null) 
01 January 1601 00:00:00 

如果您想要一个DateTime为空,你必须使用Nullable DateTime

+0

是的,我做了一些更多的研究,并最终弄清楚了它。谢谢! – Joseph