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

Powershell 什么是dsCorePropagation属性?我的脚本为什么使用它?,powershell,active-directory,Powershell,Active Directory,因此,我有一个脚本,其中我查询LastLogonTimeStamp属性并在两个条件下删除帐户,一个是它们属于两个安全组,另一个是它们在75天内没有登录到计算机。以下是我的脚本: $75DayExemptGroup = Get-ADGroup -Identity "AccountComplianceExemption_75DayLimit" | Select -exp DistinguishedName $AccountInactvityGroupMembers = Get-ADGroup -Id

因此,我有一个脚本,其中我查询LastLogonTimeStamp属性并在两个条件下删除帐户,一个是它们属于两个安全组,另一个是它们在75天内没有登录到计算机。以下是我的脚本:

$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 = ""
    }
}
所以我运行脚本,对吗?两个组中都有3个用户,对吗?然后有一个用户低于75天标记,一个用户高于75天标记,还有一个用户从未登录,因此在广告对象中显示“
”。现在,当我的脚本比较从未登录的用户的$LastLogonDate变量时,它会显示日期“1601年1月1日上午4:30:00”。现在,我想当值为null或0时,这是某种默认值,但我仔细查看了ADUC对象,它在“dsCorePropagation”属性中显示了该日期。当我在Powershell中查询它时,它显示了该日期,但当我查看AD对象上的该属性时,它包含“0”的十六进制代码


我的脚本之所以能够正常工作,是因为我将$fullADUser.LastLogonTimeStamp与null进行了比较,我只是想了解一下为什么$LastLogonDate变量不是null,因为$fullADUser.LastLogonTimeStamp是null。

因为System.DateTime是不可为null的类型,所以如果您从FILETIME传递null或零值,它将只返回最小FileTime值,即01/01/1601

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

如果你想让DateTime为空,你必须使用

是的,我做了一些进一步的研究,最终弄明白了它的意义。谢谢