DFS Replication Report Task

This is an earlier piece of code (says 1/21/2007).  I don’t do a lot with batch files anymore…however, it looks like this could still work and I thought I’d copy it here.

Purpose: Create Distributed File System (DFS) Replication Health Reports, post them to a web site and send an email notification when complete. This script was designed to run as a scheduled task.

Tested Windows Version(s): Windows 2003 R2
Script language: standard batch file


REM ================================================================================ REM ====================== DFS Replication Report Generation ======================
REM ================================================================================
REM Created by Brian Wuchner on 1/19/2007

SET ReplicationGroup=server1\web_replication\webdev
SET DestinationOutputPath=D:\Inetpub\wwwroot\webdev.domain.alias\ReplicationReport
SET DestinationWebOutput=http://webdev.domain.alias/ReplicationReport
SET SendSMTPnotification=yes

REM Optional settings for email notifcation
SET BlatSMTPmailPath="D:\SCRIPT\BLAT\blat.exe"
SET SMTP_Server_Address=smtp_server.com
SET SMTP_From_Address=scripter@domain.alias
SET SMTP_To_Address=scripter@domain.alias
@ECHO OFF
CLS

REM Use the for command to format date and time as YYYY-MM-DD HHMM
for /F "eol=; tokens=1,2,3,4* delims=/, " %%i in ('date /t') do SET YYYYMMDD=%%l-%%j-%%k
for /F "eol=; tokens=1,2,3* delims=:, " %%i in ('time /t') do SET HHMM=%%i%%j%%k

DFSRadmin health new /rgname:%ReplicationGroup% /repname:"%DestinationOutputPath%\%YYYYMMDD%_%HHMM%.html"

if %SendSMTPnotification%==yes %BlatSMTPmailPath% -server %SMTP_Server_Address% -f %SMTP_From_Address% -to %SMTP_To_Address% -subject "DFS Replication Report %YYYYMMDD%_%HHMM%" -body "The DFS Replication Report for replication group %ReplicationGroup% dated %YYYYMMDD%_%HHMM% has completed and is ready for review. You may access the report here: %DestinationWebOutput%/%YYYYMMDD%_%HHMM%.html. This report was sent from %computername% by %userdomain%\%username%."
exit

Posted in Scripting | Leave a comment

Add domain group to local group

This script was designed to be run by a domain administrator to grant other groups access to Administrators or Power Users on a local machine.  It reads in a list of computers from a text file and attempts to add the specified domain group to a specified local group.  An error log (success, fail, error message) will be written so that you know which workstations were correctly updated.

This is a useful script to grant a desktop support group access to a list of workstations without giving them domain administrator permissions.


On Error Resume Next

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oInFile = oFSO.OpenTextFile("computers.txt")
Set oLogFile = oFSO.OpenTextFile("Output.log",8,True)
StartTime = Now
ComputerCount = 0

While Not oInFile.AtEndOfStream
sComputerName = Trim(oInFile.ReadLine)
If Not sComputerName = "" Then
ComputerCount = ComputerCount + 1
sLGroup = "Administrators"
sGGroup = "Workstation Admins"
sDC = "testing.root.local"

Message = "Error adding Global to Local on " & sComputerName

Set oLGroup = GetObject("WinNT://" & sComputerName & "/" & sLGroup & ",group")
Set oGGroup = GetObject("WinNT://" & sDC & "/" & sGGroup & ",group")
ReturnCode = oLGroup.Add(oGGroup.ADsPath)

If Err.Number = "-2147023518" then
Message = sGGroup & " is already a member of " & sLGroup & " on " & sComputerName
ElseIf Err.Number = "0" Then
Message = oGGroup.Name & " is now in " & oLGroup.Name & " on computer " & sComputerName
End If

oLogFile.WriteLine (Message)
End If
Wend

MsgBox ComputerCount & " machines were processed in " & DateDiff("S", StartTime, Now) & " seconds."

WScript.Quit

Posted in Scripting | Leave a comment

New web site!

Good morning,

If you are reading this, you’ve obviously found my new blog.  I’ve created this site to discuss random topics in virtualization and systems administration.  Over the next couple of days I plan on consolidating a few failed attempts at creating such a site into this new structure.

If you have any comments or suggestions please feel free to post them.

Thanks,
Brian Wuchner

Posted in Uncategorized | Leave a comment