Category Archives: windows 2008

PowerShell Script Run Time

Quick how to on getting the length of time your script ran.

##Beginning of the script.
$startTime = get-date;

##Your code here

##End of script
$endTime = get-date;
$runTime = $endTime – $startTime;


List Files Last Modified 30 Days

How to list files last modified in the last 30 days via Powershell.  Run these commands in the directory containing the files to filter.

$lastModAge = (get-date).adddays(-30);
Get-ChildItem | Where { $_.LastWriteTime -gt $lastModAge }

NSLookup Sweep

I keep finding the need to find an open IP address for a new server, and I get tired of searching manually.  I am also not patient enough for a ping sweep, so I created a nslookup sweep with powershell. The nslookup sweep just looks through a subnet to find the first address without a dns entry. The next step just requires you to ping the address to insure it’s not being used.  Check out this post for a TCP Port Scanner in PowerShell.

$i = "1";
$subnet = "192.168.1";
while ( $i -lt 255 ) {
$ipaddr = "$subnet.$i"
$nsResult = nslookup $ipaddr 2>&1 | select-string "Name";
if ( $nsResult ) {
echo "$ipaddr is available";
$i = "256";

PowerCLI and Storage

Below are some interesting sets of PowerCLI commands that will give you more information on your VM’s hard drives and your datastores.

The below will give you the total allocated hard drive space of all the VM’s in a cluster.

Get-Cluster "Cluster Name" | get-vm | Get-HardDisk | %{ $vmCapacity += $_.capacityKB }

The below will give you the Total Capacity, Free Space, and Usage of your datastores.

Get-Datastore | %{ $datastoreFreeSpace += $_.FreeSpaceMB }
Get-Datastore | %{ $datastoreTotalCapacity += $_.CapacityMB }
$datastoreUsageTotal = $datastoreTotalCapacity - $datastoreFreeSpace

write-host "Total Capacity: $datastoreTotalCapacity MBs"
write-host "Total Free Space: $datastoreFreeSpace MBs"
write-host "Total Usage: $datastoreUsageTotal MBs"

vSphere Resource Allocation and Memory Ballooning

Recently I increased the amount of RAM on a VM, but I forgot to increase the Limit – MB under the Resource Allocation tab on the pool. So my VM had 6144MBs of RAM but was only allowed 4096MBs. Because of this the VM tools on the VM thought that the ESX Host was running low on physical memory and started the ballooning process. This caused the memory usage on the VM to go through the roof, causing the VM to have major issues.

To fix this issue, I set the Limit – MB to the amount of memory I had assigned to the VM and the VM’s memory usage drastically went down.

So to summarize my findings… If the Limit – MB is set lower than the amount of memory the VM has, it can cause ballooning. Also if the VM is getting close to using the set limit then it could cause ballooning.

For more information on vSphere Memory usage, and Memory Ballooning check out the links below.

Activate Office 2010 with KMS Server

Step one, make sure you have a KMS server and you have set it up for Office 2010.  If not, check out my post on setting up your KMS server Office 2010.

Activating Office 2010 with your KMS Server

Open an elevated command prompt on your client with Office 2010 installed.

Change directory into your Office installation directory cd “C:\Program Files\Office 2010\”

Then change directory into office14 cd office14\

Now run ospp.vbs /sethst:kmsserver.yourdomain

The above command set’s your KMS Server (replace kmsserver.yourdomain with your server’s name)

Then run ospp.vbs /act

The above command activates your Office 2010 with your KMS server

Now close your command prompt, you are good to go.

Setup KMS Server for Office 2010

Log into your Windows Server 2008 R2 KMS Server or server to be.

Download KeyManagementServiceHost.exe file from the MS Office KMS Host License Pack page

Now run the KeyManagementServiceHost.exe file.

Enter your KMS Host Key when it asks.

Then just continue with activation when prompted.

More information on KMS Servers and Office 2010 can be found here.