Managing large ActiveDirectory estates can often be a challenge, especially when you have a large group of AD administrators controlling group access.. This nifty little VBScript can be used to enumerate all the members of an AD Group. Handy for regular maintenance tasks.

This VBScript could easily be adapted to out put the list to a file, or even embedded inside a larger application which performs automated maintenance tasks.



TermiatorUsing this very simple straight foreword vbscript, you can cycle through all currently running processes and kill the one you name below.

This can be handy if you have an application/instance which has become non responsive, such as IE when loading flash based pages maybe…

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")

Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'iexplore.exe'")
	resp = msgbox("All internet explorer windows must be closed in order to continue" & vbCrLf & "Click Yes to close them now or No to cancel", vbYesNo)
	
For Each objProcess in colProcessList
If resp = vbNo Then
		'Nothing To do
	Else
		objProcess.Terminate()
	End If
Next


SophosI was recently approached by one of my colleagues with a dilemma, he had to go round our 30+ servers and stop and start a couple of Sophos’s Windows Services.

Now, as you can imagine this was starting to look like a fairly large and mundane task. Which is when I came up with this little VBScript.

Using this script below, you can pass it a text file with a list of machines you would like it to perform the process on.

In the script below you will see a “” change this to your text file containing machines, full file path.

The format of the text file is one machine per line.

This script is by no means ‘bullet proof’ and could be enhanced easily with little time and effort. It could also be modfied to stopstart any services you like.

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("", ForReading)

Do Until objTextFile.AtEndOfStream
    strComputer = objTextFile.Readline

	Set objWMIService = GetObject("winmgmts:" _
	    & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")

	Set colServiceList = objWMIService.ExecQuery _
	    ("Select * from Win32_Service where Name='Sophos Message Router'")

	For Each objService in colServiceList
	    errReturn = objService.StopService()
	    WScript.Echo errReturn
	Next

	Wscript.Sleep 20000

	Set colServiceList = objWMIService.ExecQuery _
	    ("Select * from Win32_Service where Name='Sophos Message Router'")

	For Each objService in colServiceList
	    errReturn = objService.StartService()
	    WScript.Echo errReturn
	Next

Loop


I was approached a few days ago to develop a solution for monitoring access to a folder on a server (with auditing enabled). My first approach was to try and monitor the files last access time, but I found this to be somewhat unreliable. So my next method was to monitor the systems event logs. This proved much more reliable. If not a little too much at times.

Drop the code below in a .vbs file, execute and sit back and relax.

strComputer =  'TODO: Enter the servers name here
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate, (Security)}!\" & _
strComputer & "rootcimv2")

Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("Select * from __instancecreationevent where " _
& "TargetInstance isa 'Win32_NTLogEvent' " _
& "and TargetInstance.EventCode = '560' " ) 'TODO: modify the event code to fire on what ever you require

Do
Set objLatestEvent = colMonitoredEvents.NextEvent
strAlertToSend = objLatestEvent.TargetInstance.User _
& " has accessed a folder on a server"   'TODO: Modify the alert you would like to receive
Wscript.Echo strAlertToSend

Set objEmail = CreateObject("CDO.Message")

objEmail.From = 'TODO: Specify a from address
objEmail.To = 'TODO: Enter a To address
objEmail.Subject = strAlertToSend
objEmail.Textbody = strAlertToSend
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
'TODO: Specify your mail servers name here
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
Loop


The following vbs script will list all of the currently installed Microsoft Hotfixes as per their KB number, a brief description, there installation date and who it was installed by. You may want to pass the computer name, to check a remote computer. Leaving as is will run the scan on the local machine.

Also you may find it beneficial to output this to an excel spreadsheet or a CSV etc.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")

Set colQuickFixes = objWMIService.ExecQuery _
    ("Select * from Win32_QuickFixEngineering")

For Each objQuickFix in colQuickFixes
    Wscript.Echo "Computer: " & objQuickFix.CSName



Page 1 of 3123