
ドメインに参加しているコンピューターには 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 でファイルをダブルクリックすると、マシン名を入力できるボックスがポップアップ表示され、ドメインを照会して、そのマシンのパスワードが最後に変更された日時が通知されます。
仮想マシンのスナップショットを定期的に復元している場合は、イメージを保存する前に、それらのマシンのセキュリティ ポリシーを確認する価値があるかもしれません。ドメイン GPO がそれを上書きせず、セキュリティ ポリシーが次のようなことを許可していると仮定すると、マシンのパスワード リセット間隔を最大 999 日まで簡単に変更できます。
[スタート] をクリックし、[実行] をクリックして、「Gpedit.msc」と入力し、Enter キーを押します。
[ローカル コンピューター ポリシー]、[コンピューターの構成]、[Windows の設定]、[セキュリティ設定]、[ローカル ポリシー]、[セキュリティ オプション] の順に展開します。
次の設定を構成します。
ドメイン メンバー: マシン アカウントのパスワード変更を無効にする (有効)
ドメイン メンバー: マシン アカウント パスワードの最大有効期間 (999 日)
ドメイン コントローラ: マシン アカウントのパスワード変更を拒否する (有効)
答え2
DCまたはRSATを搭載したコンピュータでは、dsquery computer -name ComputerName -stalepwd x
ComputerName は確認するコンピュータの名前、
x はパスワードが最後に設定されてからの日数です。
パスワードが x 日間設定されていない場合は、コンピューターの名前とコンテナーが返されます。パスワードが過去 x 日以内に設定されている場合、何も返されません。