Further Automate Disk Clean-up by Scripting

April 29, 2009

For those of you who have a need to keep your server or workstation tidy, employing an automatic file deletion script may be right up your alley. Take for instance, your web logs, sql logs, or Windows temp files. All of these files can get really out of hand if not kept in check. You also may want to keep a shared folder on your server for “file swapping” with in your local LAN. If that is the case wouldn’t you like housekeeping to be done automatically? Letting your users know it is a temporary 14 or 7 day directory may even reduce your inneroffice exchange attachments or present itself as an alternative to failed large attachement size.

Below is a script that will allow you to specify the directory paths and the number of days from the date the script is run to retain data. If you want to delete all temporary files older than 7 days, your script will look like this: cscript DeleteOldFiles.vbs C:\windows\temp 7
Obviously the meat of the script is in the “DeleteOldFiles.vbs”, which is provided below.

If you have more than one directory you need to delete files in, simply duplicate your call and replace the directory path.

Now for the Script:
option explicit

Call DoTheJob()
WScript.Echo "--- end of script execution ---"

Sub DoTheJob
dim limitDate
dim formattedLimitDate
dim folder
dim strComputer
dim objWMIService
dim colFileList
dim objFile
dim nbFiles
dim totalFiles
dim nbErrors
dim result
dim nbDays

if WScript.Arguments.Count <> 2 then
WScript.Echo “usage : DeleteOldFiles.vbs
WScript.Echo “sample: DeleteOldFiles.vbs C:\Windows\temp 90″
Exit Sub
end if

folder = WScript.Arguments(0)
nbDays = WScript.Arguments(1)

‘calculate and format limit date
limitDate = DateAdd(”d”, -1 * nbDays , Date)

formattedLimitDate = DatePart(”yyyy”, limitDate)

if DatePart(”m”, limitDate) < 10 then
formattedLimitDate = formattedLimitDate & "0"
end if
formattedLimitDate = formattedLimitDate & DatePart("m", limitDate)

if DatePart("d", limitDate) < 10 then
formattedLimitDate = formattedLimitDate & "0"
end if
formattedLimitDate = formattedLimitDate & DatePart("d", limitDate)

'show what will be done
WScript.Echo "Will remove files from " & folder & " with a date older than " & formattedLimitDate & " (" & nbDays & " days ago)"

'Get the files and delete the old ones
strComputer = "."

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

Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='" & folder & "'} Where " _
& "ResultClass = CIM_DataFile")

nbFiles = 0
totalFiles = 0
nbErrors = 0

For Each objFile In colFileList
totalFiles = totalFiles + 1
if objFile.CreationDate < formattedLimitDate then

result = objFile.Delete()

WScript.Echo objFile.Name & " - " & objFile.CreationDate & ". Delete Result: " & result
if result = 0 then
nbFiles = nbFiles + 1
else
nbErrors = nbErrors + 1
end if
end if
Next

'Show the result
Wscript.Echo "Total files in folder: " & totalFiles
WScript.Echo "Deleted files: " & nbFiles
WScript.echo "Errors: " & nbErrors
End Sub

Now the batch file that calls the clean up script:
cscript DeleteOldFiles.vbs C:\windows\temp 90

Here you will specify the path(s) you would like to clean up files and the age of the files to clean up.

Source cod provided by: http://blogs.msdn.com/benjguin/archive/2006/12/01/delete-old-files-script.aspx

Building an ESX3i White Box: Enterprise Virtualization for Less

June 25, 2008

VMWareServer virtualization is and has been a hot topic in the IT field in recent years. The use of virtualized servers allows businesses to expand their infrastructure in density (vertically) instead of in physical machine quantity (horizontally). Among other benefits this minimizes the required floor space, power consumption, and physical hardware required to keep the business running. These particular benefits are very appealing to large corporations which own and operate their own datacenters, and to the individual or small business owner who is renting rack space in a secure datacenter the savings created by server virtulization can be even more importantant. This article documents the step required to build a relatively low cost server virtualization platform with most of the features being used by billion dollar corporations today.
If you wish to try ESXi before you build a server specifically for it, simply follow the Software section of this article and plug the loaded USB drive into an available computer which can boot from a USB slot. Most computers made within the past few years should work to some degree, depending on the hardware and if ESXi comes with drivers for it.

Software
Although there are various vendors currently offering virtualization software, the leading choice among top businesses currently is VMware. VMware offers a full range of virtualization products, but for this article we will focus on their most recent release; ESXi. This software is a minimal version of their popular ESX Server product line which provides “an enterprise-class hypervisor with a thin 32 MB footprint”. It is intended to be installed on an SD card which is included with a select number of enterprise class servers from hardware vendors such as Dell, IBM, and HP. To learn more about ESXi, click the following link http://vmware.com/products/esxi/.

Edit: VMware now gives users a license of ESXi for free after registration!  You are no longer limited to a trial.
Although the licensing for ESXi is currently $495, VMware allows anyone to download a 60 day trial of the product for free. This evaluation copy was used throughout the system build, and can be upgraded to the retail copy at the end of the trial period if desired.

Note: The following instructions are a summary of the instructions found at http://vmetc.com/2008/02/05/create-your-own-bootable-esx-3i-usb-stick/ .
Since USB jump drives are much more common than PCI to SD card adaptors, we will install the software onto a >=1GB USB drive. To start, download an evaluation copy of the software (VMware ESXi 3.5 Installable Update 1) from VMware’s site http://vmware.com/download/vi/ . Next you will need to download a trial copy of WinImage (http://www.winimage.com) and a freeware arc hiver such as 7zip (http://www.7-zip.org). Then perform the following steps:

    1. Extract INSTALL.TGZ from the root directory of the ESXi ISO image using 7zip.
    2. Extract /usr/lib/vmware/installer/VMware-VMvisor-big-3.5.0-67921.i386.dd.bz2 from INSTALL.TGZ using 7zip
    3. Extract VMware-VMvisor-big-3.5.0-67921.i386.dd from VMware-VMvisor-big-3.5.0-67921.i386.dd.bz2 using 7zip
    4. Attach the USB flash drive and make sure you no longer need the data on it
    5. Use WinImage to transfer VMware-VMvisor-big-3.5.0-67921.i386.dd to the USB flash drive
    1. Disk->Restore Virtual Hard Disk image on physical drive…
    2. Select the USB flash drive (Warning: If you select the wrong disk you will lose data!)
    3. Select the image file VMware-VMvisor-big-3.5.0-67921.i386.dd
    4. Confirm the warning message
    5. Wait for the transfer to complete
    6. Unplug the USB flash drive (Warning: If you forget to unplug the flash drive from the PC you might lose the data on your hard drives the next time you boot!)

Hardware
Now that we have our bootable ESX drive, it is time to build the physical box which will host the virtual machines. Because ESX is meant to be an enterprise product, it is only sold and supported on a select number of expensive server platforms which sell for anywhere from $3000-$30,000. However even though these are the only officially supported platforms VMware lists, the ESXi hypervisor can actually work with a variety of undocumented hardware. Because of this, building a white box often involves finding out by trial and error which hardware works and which doesn’t. The following, guaranteed to work, configuration was used during my build to fit my personal needs and desired budget, but other more or less powerful configurations may also work if suitable. All of the parts used were purchased from online PC hardware providers and the prices listed may reflect currently unavailable sales or rebates.

    Part/ Price
    4U rack mountable case: Norco RPC-800 / $74
    8GB Corsair XMS2 DDR2 800 RAM (4×2GB) / $152
    Corsair CMPSU-550VX 550W Power Supply / $80
    Intel Q9300 Processor / $275
    ABIT IP35 Pro Motherboard / $130
    Intel EXPI9300PT Gigabit PCI-E Network Card (x2) / $90
    2GB Sony USB Micro Drive / $13
    Cheap PCI or PCI-E video card (only needed for setup) / $15
    1TB HDD (Western Digital Caviar SE16 WD5000AAKS SATA drive x2) / $180
    Total $1,009

    The hardware used provides a fairly beefy machine (quad core with 8GB RAM and 1TB of disk space) easily capable of running numerous virtual servers simultaneously. For example the above hardware is currently running four different VM’s each with a 3 GHz CPU core and 2GB RAM. The particular motherboard used includes two on-board gigabit NIC’s which are unfortunately not supported by ESXi at this time. Therefore, the two PCI-E Intel NIC’s were included to provide both a VM traffic and an ESX management physical Ethernet port. Because ESXi also does not support IDE devices, the hard drives used must be SATA. And although the motherboard includes onboard raid, the chipset used is only supported in IDE mode (meaning no RAID or AHCI support). If raid is desired, a raid PCI or PCI-E card may be used.

    Installation
    After setting up the physical ESX box, insert the USB drive with the newly loaded hypervisor into an available USB port. Once the box boots up, a setting needs to be configured in the bios for the server to boot from the USB drive. Under Integrated Peripherals->OnChip PCI Device->USB Device Settings make sure the USB Storage Function is set to Enabled. Then make sure the Hard Disk Boot Priority is set to have the USB drive boot first. Then save the settings and let the machine boot into ESX. You are now ready to configure the ESX server as desired.

    Final Thoughts
    Server virtualization is an increasingly important skill for IT professionals. While the system described in this article is certainly stable enough to used in a business environment, because it uses white box components and is not officially supported by VMware it is more practical for use in a “home” or lab environment. By using the above procedures ESXi gives the novice techie the ability to learn, play, and benefit from the skills required for in-demand positions in the IT field.

Save Money by using Computer Manger

May 1, 2008

This article will explore one of the most fundamental tools for troubleshooting your computer, the computer manager. With the computer manager you will be able to check your computer’s event logs, troubleshoot internal/external devices, add/remove local users, create performance alerts, and hopefully save you money by helping you fix the problem yourself. Speaking from experience, the computer manager is one of the first stops for an IT professional when diagnosing a problem. Let’s take a look at the computer manager and see what it has to offer. We’ll start by opening it.

 

Open Computer Manager

 

Right Click on My Computer Icon and goto: manage

 

Open Computer Manager

 

 

 

 

 

 

 

 

The computer manager will now be open.

 

Computer Manager

 

As you can see, the computer manager has a lot to offer just from viewing the icons. Let’s step through each one of these options.

 

System Tools

 

 

1. Event Viewer
As you may already know, the event viewer is a place where System, Application, and Security events are viewable. You can gather very valuable information from these events and can customize them to gather events from specific applications. In many cases you will be able to find the problem description from the event viewer.

 

 

2. Shared Folders
Shared Folders

 

This part of computer manager is really handy. There are three sections to shared folders, Shares, Sessions, and Open Files.

 

The first icon labeled Shares will show you exactly what shared folders or drives you currently have on your machine. This is very handy when auditing your machine for unwanted shared resources. Some applications when installed (i.e. Symantec Antivirus), create a shared folder on your machine and don’t tell you. Normally those shares do not pose any threat but if you are wanting to really lock down your machine make sure you know exactly what folders and drives you are sharing to the public. If you are unsure what the dollar sign ($) means after the share name, please read my previous journal entry on Creating a Hidden Share.

 

The second icon labeled Sessions is another great tool that allows you to view the current users logged on to your computer. This tool is most used on servers where multiple people can be terminal served into the computer for various reasons. Sessions will show you who is logged on, from what machine they are connected, any open files they may have, and how long they have been connected. If you are an administrator on your computer you may choose to disconnect an idle session by right-clicking on their username and choosing Disconnect.

 

The third and final icon labeled Open Files is a tool that allows you to view all of the open files currently on your system. This is nice if you are sharing a folder with many people on a LAN. You would need to use this function if you were trying to access a file on your machine that was being used by another person. You would receive an error that said this file is already in use by another person or program and the application would not let you edit the original file. You could then find the open file using this tool and either see who is using it or if you are an administrator, you could simply close the open file.

 

 

3. Local Users and Groups
Local Users and Groups

 

Earlier in this article I have made a few references to being Administrator, if you were unsure how to become administrator or was curious who else was, here is where you can check. Local users and groups will give you all the users and groups currently associated with your machine, it will also allow you to edit users and/or groups. First and foremost this is an excellent way to audit the user accounts that currently have access to log on to your machine. When the average user installs Windows on their machine they forget the fact that they had to create an Administrator account during the set-up process. This account usually lies dormant but sometimes, it is that account that hackers are looking for to access your machine. Take a look at the local user accounts associated with your machine by clicking on the Users folder and see if there is anything that surprises you.

 

User Accounts

 

You may notice a few user accounts besides the Administrator and Guest accounts that look strange, don’t worry, you probably don’t need them. If you are using a home computer and you don’t know what they are used for you can disable them, otherwise speak to your administrator if you have questions. I also recommend disabling the Guest account if you don’t use it.

 

Next let’s take a look at how to create a local Administrator. (you will need to be an administrator for this next section)

 

If you wanted to manage the local computer’s administrator list, you will need to venture to the groups section and find the Administrators group. By double-clicking on the Administrators group, you will see a list of users that currently have access to your local machine as an Administrator. You can add or remove a user/group by clicking add or remove at the bottom of the window. If you are connected to a domain, say at work, you may notice an entry similar to this: <your domain name>/Domain Admins. This means that anyone that is in that domain group can have administrative access to your local machine. Also, you will not see a domain user or group located in your local Users folder. (Any further explanation of domain vs. local accounts is outside the scope of this article.)

 

 

4. Performance Logs and Alerts
Performance Logs and Alerts

 

I am only going to briefly explain the uses of the Performance Logs and Alerts section of computer manager because the uses are too robust for an excerpt in an article. If you have ever heard the word Perfmon thrown around, it is in reference to this tool. Performance monitor is a highly valuable resource for diagnosing your computer. If you feel your computer is slow or it often bluescreens (BSOD), you may want to explore the options this tool has to offer. As an example, I have used this tool to pinpoint the exact application that was gradually consuming greater and greater resources over time, which eventually lead to my machine locking up. It allowed me to diagnose the problem (my computer was locking up due to a memory leak) and accurately determine the application that was causing the problem. Many more scenarios apply.

 

 

5. Device Manager
Device Manager

 

This is a great resource that I think most casual users are not aware of. This is called the device manager and it contains a list of all the connected devices on your system. Here is the place where you will want to update a driver, scan for new hardware, diagnose a hardware problem, or change advanced settings on a piece of hardware.

 

First, take a look at all of the devices currently connected to your system, there are quit a few! Lets say you are having trouble getting your speakers to work properly, they just won’t produce any sound. While it may be the fault of the speakers themselves, it is more likely the fault of your computer sound card. With device manager open you can quickly expand the Sound, video and game controllers section to see if their are any errors associated with your sound card. An error will produce a red X over the device and a warning will produce a yellow ! over the device. In most cases you can attribute a hardware problem with the driver installation. You can update a driver by double-clicking the device in question and going to the Driver tab.

 

Driver Details

 

Here you can click Update Driver.. and follow the wizard that will guide you through the process of re-installation.

 

 

 

 

 

 

 

 

 

Another function is to change advance settings of a device. For example, let’s change the duplex of the currently connected Network Interface Card (NIC). Open the device properties of your card and navigate to the Advanced tab.

 

Advanced Hardware Settings

 

You can see that I selected Link Speed / Duplex Mode and I can change it to the optimal setting for my network. Remember this is just one example of advanced hardware configurations. Also, note that available settings will vary between different hardware models.

 

 

 

 

 

 

 

 

 

 

Storage
1. Removable Storage
Removable Storage

 

 

Not many average users will be taking advantage of this section. In fact, not many advanced users will either. This tool helps you manage your removable storage, more specifically it mainly helped manage tape drives. With the rise of larger hard drives, USB drives, and Flash drives, the personal use of tape drives have become almost obsolete. Many companies still use tape drives though as a means to archive and ship offsite for safe keeping. However, companies that archive their data via tape typically use a much more robust media management tool than Removable Storage combined with NT Backup.

 

2. Disk Defragmenter
Disk Defrag

 

 

 

 

 

 

 

 

 

 

 

 

I believe we all know what disk defragmentation does. A couple of things about this tool though, you must have 15% free space on your drive to properly defragment a volume and you should defragment regularly. I set-up most of my customers with a scheduled task that automatically defragments the volume once a month. A severely fragmented volume can greatly reduce disk I/O time, which means noticeably slower speeds for you.

 

 

3. Disk Management
Disk Management

 

Disk management is useful because it displays the overall health and statistics of your connected drives. This would be especially useful if you had drives that belonged to a RAID group. The statistics and overall health of the disks can help IT personal gain a quicker understanding when troubleshooting foreign machines.

 

Services and Applications

 

In this section I am only going to cover services, as the WMI Control and Indexing Service is not normally used by end-users.

 

 

1. Services
Services

 

The Services tool does just that, displays all the native services currently loaded on your machine. You will come to find, that for whatever reason, services can stop unexpectedly, not start on boot, or run when you have no need for them. For a list of Windows services that you don’t need, please read this article: Ten Windows Services, You Don’t Need. By right-clicking a service, you can Stop, Start, Restart, or set the boot parameters to Manual, Automatic, or Disabled. For the latter you will have to enter the service properties.

 

Service Properties

 

 

 

 

 

 

 

 

 

 

 

 

 

 

For the purposes of this article, I will not elaborate any further about the roles of services.

 

That brings us to the end of the computer manager, obviously I could not expand in great detail of all it has to offer, however I am certain you can keep some money in your wallets if you use computer manager to help diagnose some of your problems. If you have a question about a subject covered here or a comment, please feel free to comment to this post.

 

I will leave you with one other tip that will help administrators really unleash the power of this tool. (for this next section you must be logged in as an administrator or be able to run computer manager as an administrator)

 

Remote Management

 

With computer manager open and the Computer Management icon highlighted, goto: Action >Connect to Another Computer…

 

Remote Management

 

 

 

 

 

 

 

 

Just enter the NETBIOS name of the computer you would like to connect to and press OK. Or you can search the domain/workgroup by clicking Browse. If you do not have the correct permissions to connect, Windows will let you know, just remember you need to be local Administrator on the remote machine to access all that Computer Manager has to offer. As you can see Computer Manager is an invaluable tool when trying to diagnose a problem on your local machine or if you are administering a LAN, on a remote machine. Because this is native to Windows there is nothing special to install or configure, so you can use it wherever you go!

 

Protecting your Identity

March 21, 2008

Identity Theft

Protect whats yours, don’t be another statistic.

Secure

” To secure your identity is to alter your way of thinking, a cautious and inquisitive mindset will help you protect your personal identification. “

What are thieves looking for? - Identity theft is almost always a crime of opportunity.

Account Information. (i.e. numbers, maiden names, card types, pin numbers, exp. dates)

Social Security Numbers.

Drivers License.

These are the three basic needs of any identity thief, however, it is important to note that any one of these may lead to troubling times. Identity theft is becoming easier and more abundant because thieves are using the internet to exchange information and sell your identity.

Ways your identity can be stolen. - Most people don’t know their identity has been stolen.

• Internet Phishing Scams - Rouge websites posing as valid sites to gain your account information.

• Credit Card “Skimmers” - Small devices that can scan a credit card and retrieve all needed information from it. This can be used to duplicate credit cards.

Phone or Email Inquiries - Someone calling or emailing you wanting you to verify account information.

Computer “Hacking” - Hackers these days are not looking to just mess with your internet site or steal your meeting minutes, hacking is big business, they want some reward for their effort. It is more likely if a hacker is attacking you or your company they know what they are looking for and they know it will produce some value for them. Internal computer hacking is a much bigger threat than a random person on the internet.

Your Person - You are sometimes the primary cause of identity theft. Keep only the nessacaties in your wallet or purse. Be conscious of your surroundings and your situation. Don’t be quick to give out information just because they ask for it. (i.e. You don’t need to give out your phone number to buy some batteries!)

Analyze the way you think, be conscious of your situation and only give out information if it is necessary. Be proactive in protecting your identity, practice it, and make it routine.

How you can protect yourself.

Ask Questions - Don’t think that the phone company needs your social security number, ask them why. Some compaines such as financial institutions need it to run a credit report, other compaines gather this information as a convenience or for their own account verifications.

Keep a separate CC for online purchases - I recommend that everyone has a separate card with a small limit, strictly for online purchases. If your card number is ever stolen, you know your purchases and your card limit will not effect your credit score.

Have an IT professional help secure your network - An IT professional will be able to find security holes that you may not be aware of, remember it is their job to stay current with technology.

Internet Consciousness - Don’t reply to rouge emails, watch out for insecure websites. If you are making a purchase or checking your account information make sure the site is secure (https://) and there is not a certificate violation.

Check your financial records - Check your bank statements each month, look for unusual purchases. Online banking has made it easier to check your purchases with real-time updates. Be aware of your credit score, monitor it regularly, monitor it regularly, monitoring does NOT lower your score.

Protect your documents - Keep your important documents in a secure place, like a lockbox or safe. Destroy your mail, shred any evidence of your existence in your mail. Don’t let a dumpster diver find you. Secure your laptop and thumbdrives, these portable devices can sometimes contain very personal information about you or your company, make sure they are readable by you only.

” There are an infinite number of ways your identity can be compromised, protecting it starts with you. “