網域電腦帳戶計畫何時變更密碼?

網域電腦帳戶計畫何時變更密碼?

據我了解,加入網域的電腦在 AD 中擁有電腦帳戶,這些帳戶的密碼會過期(預設情況下顯然每 30 天),並且這些密碼會自動更改,無需使用者乾預。

鑑於已知這在恢復加入網域的虛擬機器快照時會導致問題,是否可以查詢加入網域的電腦或 AD 以確定下次計劃更改電腦帳戶密碼的時間?

答案1

可以為此查詢​​網域,下面的腳本將告訴您上次重置特定電腦的網域密碼的時間。

'Replace "yourdom.com" with your domain name.
DomainName = "yourdom.com"

querymachine = UCase(inputbox("Enter full machine name"))
lngBias = 2

'****************Setup Log file******************************************************

Set fso = CreateObject("Scripting.FileSystemObject")
'The 8 in this line will append to an existing file, replace with a 2 to override
set txtStream = fso.OpenTextFile("System.txt", 8, True)
txtStream.WriteLine "Ran on " & Date & " *******************************"

'****************Setup ADSI connection and populate ADSI Collection******************

Set objADOconnADSI = CreateObject("ADODB.Connection")
objADOconnADSI.Open "Provider=ADsDSOObject;"
Set objCommandADSI = CreateObject("ADODB.Command")
objCommandADSI.ActiveConnection = objADOconnADSI
'there is a 1000 object default if these next 2 lines are omited.
objCommandADSI.Properties("Size Limit")= 100000
objCommandADSI.Properties("Page Size")= 100000
objCommandADSI.Properties("Sort on") = "sAMAccountName"
objCommandADSI.CommandText = "<LDAP://" & DomainName & ">;(objectClass=computer);sAMAccountName,pwdLastSet,name,distinguishedname,operatingSystem;subtree"
Set objRSADSI = objCommandADSI.Execute

'Loop through record set and compare machine name*************************************

do while NOT objRSADSI.EOF
    if not isnull(objRSADSI.Fields("distinguishedname")) and objRSADSI.Fields("distinguishedname") <> "" then
    objDate = objRSADSI.Fields("PwdLastSet")
    'Go to function to make sense of the PwdLastSet value from AD for the machine account.
    dtmPwdLastSet = Integer8Date(objDate, lngBias)
    'calculate the current age of the password.
    DiffADate = DateDiff("d", dtmPwdLastSet, Now)

    'Is the machine the one we're looking for?
        if UCase(objRSADSI.Fields("name")) = querymachine then
        txtStream.WriteLine objRSADSI.Fields("name") & ";" & dtmPwdLastSet & ";" & DiffADate & ";" & objRSADSI.Fields("operatingSystem") 
        wscript.echo objRSADSI.Fields("name") & ", Last set: " & dtmPwdLastSet & ", Days since last change: " & DiffADate
        end if
    end if
objRSADSI.MoveNext
loop
wscript.echo "Done!"



Function Integer8Date(objDate, lngBias)
' Function to convert Integer8 (64-bit) value to a date, adjusted for
' local time zone bias.
Dim lngAdjust, lngDate, lngHigh, lngLow
lngAdjust = lngBias
lngHigh = objDate.HighPart
lngLow = objdate.LowPart
' Account for bug in IADslargeInteger property methods.
If lngLow < 0 Then
lngHigh = lngHigh + 1
End If
If (lngHigh = 0) And (lngLow = 0) Then
lngAdjust = 0
End If
lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
+ lngLow) / 600000000 - lngAdjust) / 1440
Integer8Date = CDate(lngDate)
End Function 

(我很想對上面的腳本表示感謝,但它已經從一個人傳到另一個人並以各種方式進行修改,我不知道它最初來自哪裡)

將其另存為類似 MachinePasswordDate.vbs 的文件,在 Windows 中雙擊該文件應該會彈出一個框,您可以在其中輸入計算機名稱,然後該框應該查詢域並告訴您該計算機的密碼上次更改的時間。

如果您定期還原虛擬機器快照,那麼在儲存映像之前可能值得查看這些電腦上的安全性原則。您可以輕鬆地將電腦密碼重設間隔變更為最多 999 天,前提是您的網域 GPO 不會覆寫它,而您的安全性原則允許此類操作:

按一下“開始”,按一下“執行”,鍵入 Gpedit.msc,然後按 Enter。

依序展開“本機電腦原則”、“電腦設定”、“Windows 設定”、“安全性設定”、“本機原則”,然後展開“安全性選項”。

配置以下設定:

  • 網域成員:停用電腦帳戶密碼變更(已啟用)

  • 網域成員:機器帳號密碼最長期限(999 天)

  • 網域控制器:拒絕機器帳戶密碼變更(已啟用)

答案2

在 DC 或任何具有 RSAT 的電腦上,您可以運行dsquery computer -name ComputerName -stalepwd x

ComputerName 是您要檢查的電腦的名稱
x 是自上次設定密碼以來的天數。

如果自 x 天以來未設定密碼,它將傳回電腦的名稱和容器。如果密碼是在最近 x 天內設定的,則不會傳回任何內容。

相關內容