Friday, May 30, 2014

Scripting Replication of All Domain Controllers in a Site

I have been looking for a way to replicate all servers for a while but it seems that Microsoft doesn't want the KCC to function this way.  Repadmin seems to replicate (with /syncall) to only its configured replication partners.  Now if you use the /e it will replicate (to the best of my understanding) to domain controllers in other sites if they are configured as a partner.  So I found a way to do this using two commands, dsquery.exe and for.exe.  Dsquery is a powerful Microsoft tool that's been around for a while and allows for all sorts of functionality in the area of "Directory Services".  As a side note you can pipe in other "DS" commands such as dsadd, dsmod, dsmove, dsrm based on the former part of the query.
Anyway, just plug this script into a batch file, replacing SITENAME with the AD site you wish to replicate in and change the path to wherever you run your scripts from.

----------script begin --------------
dsquery server -o rdn -site "SITENAME" >C:\scripts\SITENAMEDCs.txt
For /F "delims=" %%i in (SITENAMEDCs.txt) do repadmin /syncall  %%~i
--------script end-------------------
The dsquery command will output the servers in the site one per line, surrounded in quotes.   The second line looks at each line in the file and runs the repadmin /syncall command.   The ~ in the latter part of the "for" line is used to parse the quotes that dsquery outputs in. Enjoy!


Thursday, March 13, 2014

Windows 2012 R2 Random Reboots: Wininit.exe Has Initiated a Restart for the following reason: No title for this reason could be found Reason Code: 0x50006

By the time many of you read this you will have had the patch for this, but in case anyone brings up a domain controller or has object success/failure auditing enabled without this patch this will help.  I had servers rebooting seemingly randomly, and of course the log entries were no hel.  I thought it was the VMware customization process and/or the VMWare network driver.

It turned out to be a known bug in 2012 R2, when the server (or in my case, domain controller policy) has auditing enabled.  I was able to test by renaming objects on these DCs, and sure enough the "Windows Detected a Problem and Will Restart" message popped up.

One option is to turn off auditing.  This wasn't an option for me, as there is a somewhat heavy compliance requirement for it where I am.  Anyway they released this patch on 3/10/14 and you can download it without the call to Microsoft now. It is part of a rollup patch but I installed the standalone and the issue went away.

http://support.microsoft.com/kb/2928680/en-us

Tuesday, February 18, 2014

Measure Uptime via VB and WMI on Windows 2000

I had the need to remotely monitor the uptime of a Windows 2000 server, so that I can get an alarm if it was up more than 25 hours.  I had to report it in a certain format and the output needed to be a simple whole number.  After finding some existing scripts out there, I eventually found that the output would show correctly on any OS later than Windows 2000. However on W2k it was reporting with 5 hours added on.  I changed the script to include an operator to subtract 5.  Hope this helps someone else I spent entirely too much time on this!

--------code----------
Option Explicit
     Dim objOS, dateLastBoot, nSystemUptime
     Dim nDays, nHours, nMinutes
     '
     ' Get the Windows Home Server OS object
     '

     For Each objOS in GetObject( _
         "winmgmts:\\).InstancesOf ("Win32_OperatingSystem")
         '
         ' Return the last boot up time and
         ' convert it to a Date object
         '
         dateLastBoot = ConvertToDate(objOS.LastBootUpTime)
         '
         ' Calculate the number of minutes between then and now
         '
         nSystemUptime = DateDiff("n", dateLastBoot, Now)
Wscript.Echo "Message: Uptime Alarm"
Wscript.Echo "Data:"
Wscript.Echo "Uptime" &vbTab & Int( nSystemUptime / 60 - 5 )
         ' Convert the total minutes into hours, days, and minutes
         '
         'nDays = Int(nSystemUptime / 1440)
         'nHours = Int (((nSystemUptime / 1440) - nDays) * 24)
         'nMinutes = nSystemUptime Mod 60
         '
         ' Display the result
         '
         'Wscript.Echo "Last Boot: " & dateLastBoot & vbCrLf & _
         '             "System Uptime: " & _
         '             nDays & " days and " & _
         '             nHours & " hours and " & _
         '             nMinutes & " minutes"
     Next
     '
     ' This function takes a datetime string and converts
     ' it to a real date and time object
     '
     Function ConvertToDate(strDate)
         Dim strYear, strMonth, strDay
         Dim strHour, strMinute, strSecond
         strYear = Left(strDate, 4)
         strMonth = Mid(strDate, 5, 2)
         strDay = Mid(strDate, 7, 2)
         strHour = Mid(strDate, 9, 2)
         strMinute = Mid(strDate, 11, 2)
         strSecond = Mid(strDate, 13, 2)
         ConvertToDate = DateSerial(strYear, strMonth, strDay) & " " & _
                    TimeSerial(strHour, strMinute, strSecond)
End Function
-----code end-------------