A chronicle of an IT pro's adventures, whims and wants, his goals and hopes. A collection of his photos and stories.
Monday, July 6, 2009
Microsoft Technet Summer Scripting Games : Javelin Throw
Thursday, June 25, 2009
Checking for Remote Desktop Status of a Remote Server
Wednesday, June 24, 2009
List Local Users of Remote Systems (Powershell)
Tuesday, March 31, 2009
Rebooting a computer (VBS)

The user has the option to proceed with the reboot or he can choose to click the "No" button and abort the reboot. Clicking "Yes" will invoke the ShutMeDown procedure which uses the .Reboot method to reboot the computer. Clicking "No" will display the following pop-up:

Not clicking on either the "Yes" or "No" after 60 seconds will abort the script from continuing.
For what possible situations can this script be used? Follow the discussing from the following thread in The Official Scripting Guys Forum on Technet:
http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/65e8699f-fca4-4e08-a181-8b621acbf963
Monday, March 30, 2009
Enumerating Members of a Group (including Nested Groups)
This is the main body of the script. I have, for this example, three sites where two groups are being queried (one group, for example, is EU-ServerAdmins-G). There is a call in the main body to the EnumGroups function where three parameters are passed - strSite, strDN and strGroupName).
The EnumGroups function queries the strDN parameter where its members are checked. In the Select-Case loop, the object class is further checked; if the object is a group by itself, the function executes again with this group as part of the parameters passed (hence, nested groups will also be queried).
The output of this script is written onto a file (groups.csv). An example output file would look like this:
Monday, March 23, 2009
Stopping and Restarting Multiple Services using VBS
This script was created for the following thread from the Microsoft Technet's The Official Scripting Guys Forum:
http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/3db5d54d-1d7f-46c5-9129-2130a7bdfaa8/
Friday, February 27, 2009
Moderating the "The Official Scripting Guys" Forum in Technet
Thursday, February 12, 2009
Checking for the Uptime of a Remote Computer
The main body checks for 1 argument passed when the script is ran; if the number of arguments is not equal to 1, then the script exits. It then calls for the GetUptime procedure:
The GetUptime procedure queries WMI for the Win32_PerfRawData_PerfOS_System class, in particular the Timestamp_Object, Frequency_Object, and the SystemUpTime properties. To calculate for the system uptime in seconds (in my example, I used the iUptimeInSec variable), the following formula was used:
iUptimeInSec = (intPerfTimeStamp - intCounter)/intPerfTimeFreq
This value is then passed to the ConvertTime(seconds) function.
The iUptimeInSec variable was converted to an easier-t0-read format, eg. days, hours, minutes and seconds.
Monday, January 19, 2009
Identifying the current logged in user of a remote host
Thursday, January 8, 2009
Conficker.vbs - Conficker (Worm_DownAD) Detector
Tuesday, November 18, 2008
Deleting *.bak Files When the Computer Turns Idle (VBS)
http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/2991aa59-07c6-413e-8bf0-9ffa2bd8f0d3
Here is a script that deletes all *.bak files on a computer's D: drive when the computer becomes idle after 10 minutes.
There is actually a trick behind this script. Using a script to check whether a computer is idle is not really straightforward, but rather relatively complicated (read my lips, I don't know how to do it). I made use of the Screen Saver timeout property via a registry hack, setting it to trigger after 10 minutes (600 seconds) via the sub procedure SetScrSvrTime():
The script checks if the screen saver process is running (it is implied that in this example, the computer is configured with the "Mystify.scr" screen saver). A connection to the WMI service on the local computer is made and an event notification query which fetches within 20 seconds a list of running processes:
The Do-While loop processes the information gathered from this query and checks for the screen saver "Mystify.scr" process. If found, it goes to another loop where a call to the DelFiles(strDrv) sub procedure is launched (strDrv is the parameter passed to the sub procedure which is actually the drive where the *.bak files are going to be deleted). This sub procedure then recursively checks and deletes all *.bak files found:
This script can be further customize to accomplish other things when the computer goes idle. For example, you may want to send out notification, defrag the hard disk, run a back-up and so on. The possibilities are endless, let your imagination loose!
For those interested to have a copy of this script, please drop this post a comment.
Friday, November 14, 2008
VBS Logoff Script to Log User Information
Part 1:
http://badzmanaois.blogspot.com/2008/11/script-to-track-local-logins-vbs.html
Here's a follow-up of the login script posted earlier. This is executed when the user logs off. It will log the following information to the output log file:
Event Type (Login/Logoff)
User (Full User Name)
Computer
Date & Time of the Event
The output log file looks like this:
The script defines the location and name of the output log file (C:\LogFile\Login.csv) and calls the sub procedure Main:
The sub procedure Main checks for the current logged in user's account properties such as .UserName, .DomainName, and .ComputerName. The user's full name is then extracted and is passed to the log file (together with the other earlier-mentioned variables):
The user must have modify permission on the output log file.
Wednesday, November 5, 2008
Script to Track Local Logins (VBS)
I would suggest saving the login/logoff events on a log file in a more user-friendly format for easier analysis. For example, one may want to keep track of login time for monitoring purposes while another may do this to ensure optimal usage, for example, on a shared PC where users are allocated certain hours of access.
Heres a script that saves the login information (event ID 528) on a CSV file; the user name, hostname, and the time of login are captured.
The script opens a file (or creates one if the file does not exist) for appending wherein the captured data are stored. It then calls a sub procedure called Main to extract these information. Note that users must have modify rights on the C:\LogFile\Login.csv file.
The Main sub procedure captures the current logged in user's name, domain and the hostname of the computer and then writes these information, together with the type of action (Login) and time, to the log file:
Saturday, November 1, 2008
Remotely Removing Users from the Local Administrators Group (VBS)
Tuesday, October 28, 2008
So I got PW3ND, now what? (MS08-067)

Monday, October 27, 2008
How to Retrieve CPU and Memory Utilization using a script (VBS)
Sunday, October 19, 2008
How to disable User Account Control in Windows Vista (vbs)

Friday, October 3, 2008
Checking for Password Complexity Using Regular Expressions
| Symbol | Function |
| {x} | Match exactly x occurrences of a regular expression. |
| {x,} | Match x or more occurrences of a regular expression. |
| {x,y} | Matches x to y number of occurrences of a regular expression. |
| ? | Match zero or one occurrences. Equivalent to {0,1}. |
| * | Match zero or more occurrences. Equivalent to {0,}. |
| + | Match one or more occurrences. Equivalent to {1,}. |
| Symbol | Function |
| ^ | Only match the beginning of a string. |
| $ | Only match the ending of a string. |
| \b | Matches any word boundary |
| \B | Matches any non-word boundary |
Saturday, September 20, 2008
Adding Pictures to an Active Directory Account
I was hoping someone could explain the use of User Account pictures in 2008, is this feature expected to be integrated into AD at some point?We are setting up 2008 Terminal Services and what I would like to do is automate the user account pictures for my users and link them to a central store of pictures. So if User "Alan Other" logs in he gets "AlanOther.bmp" pulled into his profile and set as his Picture.I can script the fie moves etc, but what I can't seem to find is where to set the picture in the Reigistry.The only thing currently open to us is to standarise the picture using Group Policy.Anyone any ideas?
Thursday, September 11, 2008
Changing a User's Profile Path (VBS)
One such script delves on changing the "profilePath" property of thousands of users (this one is from the Technet forum). Being the KISS (that is "Keep It Simple and Straightforward" for you) advocate that is me, I went to create a simple, short, quick and dirty script.
First, I had to generate a list of all the users in my domain. I can, in fact, accomplish this using adsi within the main script itself. However, the fastest way to do it is actually running the net users /domain command from the CLI and piping the output to users.ini.
The ChangeUserProfilePath sub-routine has the old and the new profile paths defined (oldProfile and newProfile). The Replace string function is used to substitute oldProfile with newProfile. The resulting string, strNewProfilePath, is then set to the "profilePath" property of the user account being processed. An initial check is made to verify if the oldProfile string is located in the user's profile property (sUser.Profile). If and only if this condition is met is the profilePath updated.

