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.
Tuesday, November 25, 2008
Walkthrough: Boot WinPE on a USB Thumbdrive

The WinPE image I was using to boot up is in an ISO format. I used MagicISO to mount the ISO file to access the image's folder structure and its files. Once I had the files and folders ready, I had to do the following steps to be able to boot from my USB thumbdrive:
- list disk - displays disk information including disk number, size, and status
- select disk x - focuses all subsequent commands on a particular disk
- clean - cleans and removes all configuration information from the disk
- create partition primary - create a partition (of type primary in our example)
- list partition - displays partition information of the disk in focus
- select partition y - moves the focus to the partition y
- active - marks the partition in focus as the active boot partition
- format fs=fat32 - formats the active partition with the FAT32 file system
- assign - assigns a drive letter (the next available one) to the disk

I then copied mounted my WinPE ISO and copied the files/folders to the USB thumbdrive. And off I go, booting up WinPE from my {Insiders} USB thumbdrive.
Wednesday, November 19, 2008
Microsoft To Phase-out Live OneCare
Microsoft also announced that sales of the Windows Live OneCare subscription service as well as Windows Live OneCare for Server on SBS 2008 will end on June 30, 2009. OneCare users will have the option to move to Morro (it will be available everywhere OneCare currently is). The fact that Morro is FOC may also entice end-user adoption. However, I doubt it is capable of dislodging the industry leaders off their roosts in the enterprise security field.
Microsoft's entry to the consumer/enterprise security market way back in 2006 was met with mixed reactions. And with this setback, whatever is left of Microsoft's foothold on this arena has taken a major beating.
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.
Wednesday, November 12, 2008
Microsoft Fixes 7-Year Old Flaw + MS08-068 Exploit
Apparently, it took Microsoft 7 years to finally address this vulnerability as mentioned here. According to this article, exploit code of this flaw is currently available in the internet. In fact, Metasploit has a PoC/working exploit which runs under the 'sploit framework.
The released patch, although given just a criticality rating of "Important" (whereas, MS08-069 was rated "Critical"), appears more interesting given the fact that this fixes a 7-year old flaw.
Going back to the SMBRelay tool, here are some switches and parameters that the tool uses:
Usage: smbrelay [options]
Options:
/D num - Set debug level, current valid levels: 0 (none), 1, 2 (Default is 0)
/E - Enumerates interfaces and their indexes
/IL num - Set the interface index to use when adding local IP addresses
/IR num - Set the interface index to use when adding relay IP addresses
Defaults to 1. Use /E to display the adapter indexes
/L[+] IP - Set the local IP to listen on for incoming NetBIOS connections
Use + to first add the IP address to the NIC
Defaults to primary host IP
/R[-] IP - Set the starting relay IP address to use
Use - to NOT first add each relay IP address to the NIC
Defaults to 192.1.1.1
/S name - Set the source machine name
Defaults to CDC4EVER
SMBRelay2, on the other hand, has the following switches and parameters:
SMBRelay2 [Options]
Options:
/A LanaNum - Use LanaNum
Defaults to 0
/D DebugLevel - Level of debug messages, valid levels 0 - 3
Defaults to 0
/L LocalName - Listen for primary connection on LocalName
Defaults to SERVER
/R RelayName - Listen for relay connection on RelayName
Defaults to RELAY
/S SourceName - Use SourceName when connecting to target
Defaults to CDC4EVER
/T TargetName - Connect to TargetName for relay
Defaults to connecting back to client
Monday, November 10, 2008
Microsoft Security Bulletin Advance Notification for November 2008
The usual heads-up from Microsoft for this month mentions two vulnerabilities, one critical and one important. The patches which will address these vulnerabilities will be released on 11 November 2008 (12 November for those in Asia-Pac) during the routine "Patch Tuesday" cycle. Both the vulnerabilities affect the Windows OS from Windows 2000 Pro/Server up to Windows Server 2008 including Windows XP/Vista and Windows Server 2003. Furthermore, a Microsoft Office component is affected. For more information on the affected OS and application plus other relevant information pertaining to the release, please visit the following link:
http://www.microsoft.com/technet/security/Bulletin/MS08-nov.mspx
Expect another busy week ahead, what with all the regression testing, deployment tests, and more that the sys admins and application owners/testers will go through prior to the productive release of the patches in an enterprise. No rest. For the wicked admins.Thursday, November 6, 2008
Offline Files Synchronization Errors (Sync Center)
KB296264 mentions about modifying the registry of Windows Servers so this doesn't apply in my case. I'm on a quest to find a solution for this. =)
Follow the ongoing thread in the Technet File Services and Storage forum:
http://social.technet.microsoft.com/Forums/en-US/winserverfiles/thread/26bc65ca-5663-4183-b15b-f49a4cb664d0
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:
Friday, October 24, 2008
Out-of-Band Microsoft Patch (MS08-067) Released
Tuesday, October 14, 2008
Windows 2008 Server Core Installation Guide
- Setting the administrative password
- Setting a static IP address
- Joining a domain
- Activating the server
- Configuring the firewall


Monday, September 29, 2008
Installing Virtual Machine Additions on Server Core
Virtual Machine Additions is a very important component to running a virtual machine. You must install Virtual Machine Additions on all virtual machines.
Virtual Machine Additions adds the following enhancements to a guest operating system:
• Improved mouse cursor tracking and control
• Greatly improved overall performance
• Virtual machine heartbeat generator
• Optional time synchronization with the clock of the physical computer
Sunday, September 21, 2008
"Command-Prompt" Ninjitsu
Not since the olden DOS days have I been fascinated with the command line interface (CLI) as with the advent of the CLI-only Windows Server 2008 Server Core.
Back then, I used to dabble in scripting batch files to automate a lot of routine tasks. For example, I would run a script to format a floppy diskette, prompt the user to insert a source diskette to be copied, runs diskcopy and labels the diskette. It was considered l33t to be able to come up with complex scripts, passing parameters and arguments, catching errorlevels and other stuff. Even the prompt itself was not spared; intricate designs were the norm back then.

This interest in CLI carried on when I worked on Solaris stuff some years back. Around this period, I also ventured in the world of different Linux distros and *nix; working on bash, sh, ksh and the other sh were part and parcel of my weekend projects mostly on perl snippets.
When Powershell was introduced two years ago, I was one of the early adopters from my team. I thought integrating a full-pledged OOP platform through scripting was heaven-sent; running cmdlets from the shell, piping results to other cmdlets was rather nifty. And the script-debugging feature available in version 2.0 is, to the syntax-challenged me, a huge huge plus.
I had my fair share of ups and downs with the different CLIs I have had the chance to play around with. But still, the good-ol' cmd.exe is my main choice, hands down. It is THE CLI for me; the one CLI to rule 'em all. In fact, at any given time, I will have a minimum of two elevated cmd.exe windows on my desktop. Be it querying the registry of a remote machine, modifying the properties of an AD account, copying files to multiple target hosts, to name a few, this is the CLI for me.
And while I'm on a CLI-induced stupor, I would like to share this Windows Command Reference from Microsoft. Again, every administrator worth his skin should be adept at using command-line tools to perform routine administrative tasks; in fact, in my case, I have an elevated command prompt (where I run all admin-related checks, scripts, tools, etc.) on my desktop as part and parcel of my day-to-day work. There seems to be a command-line tool for every admin task, be it fiddling with DNS management (dnscmd), managing AD trusts (netdom), parsing event trace logs (tracerpt), directory copying on steroids (robocopy), backing-up (wbadmin), and so on. Incorporating these tools in scripts is likewise key in automating a lot of tasks thereby allowing an administrator to do more work in a more efficient manner and in lesser amount of time. Mastery of these tools is essential for an administrator; mastering the CLI is godly.




