This past week I’ve been working on a python script to gather the used, free, and total disk space from a bunch of Windows servers. I’ve had to do this manually many times over the years for various planning tasks. This most recent time a client of ours has eaten up their SAN storage in less than a year, so I wanted to see what servers are wasting a lot of SAN storage. To figure this out, I was going to look at servers with large volumes that do not have a lot of data.

I started writing a script that uses WMI to connect to the servers and collect the information. Then I thought it would be cool to have it saved to a Google spreadsheet. After figuring out how to do that, I then wanted a way to run this on a regular basis, which requires storing a Windows login and a Google login. Obviously, you don’t want that stored in plain text or in any manner that allows someone to get your passwords. I started Googling and found a post on Pycrypto. I’m sure there are better ways to do this, but here is what I came up with.

When running the script with the configuration option, it asks you for your login information for both the servers and Google. It then puts this into XML using ElementTree. I then use PyCrypto to encrypt the XML using ElementTree’s tostring function. Lastly, I use pickle to dump the encrypted data and the IV (initialization vector) used to encrypt the string to a file.

Here’s what the code looks like.


Once the data is saved, you then have to be able to get it back out of the file. Here is the code to do that.


Let me know what you think or if there is a better way. I’m sure there is.

A client of mine is looking to give access to their ERP application to their office and plant in Shanghai. They are going to do this via Citrix, so I wanted to see what latency was like. To do this, I just setup a batch file that runs pings to both locations and outputs the results to a text file. I scheduled this to run every 4 hours. Here’s the batch file.

After running for about a week, I wrote a small python script to grab all the ping times out of the text files and give me the maximum, minimum, and average response times. You are prompted for the location of the text files and the beginning pattern, so you can get the results for each site.

Here’s the output for one location:

I know this is nothing special, but I figured I’d throw it out there in case any other newbies or sys admins need to get this information quickly without software.

I’ve been working on a script to speed up our failover to the cloud testing as I wrote about in this previous blog here. Unfortunately, I haven’t been able to dedicate time to this, so I’ve been working on it here and there. I’m pretty close to completing it, at least to do what I need it to do given the skill level I’m at.

To touch on what I was trying to accomplish again, I’ll do a quick run down of the problem I was trying to solve. We currently put in data recovery solutions that take images of the servers we’re protecting. These images are then replicated offsite to our partner. When we need to recover offsite, we have the ability to virtualize any of the images transferred offsite. To make sure everything is working, we do regular tests.

When these test are performed, we choose the instance to virtualize and we create a network to virtualize them on. Unfortunately, the way this failover works, well the way virtualization works, is a new NIC is created. When a new NIC is created the IP configuration you had on all your servers is lost. Instead, they get IPs via DHCP from the network you setup, which unfortunately doesn’t give you any options other than network address, subnet mask, and gateway. This leads to a problem where none of the servers can contact active directory, and when Windows servers can’t contact AD, they can take a long time to boot and an even longer time to login.

Another problem we have is we have agents running on the servers being protected, because we monitor them as well. When these test failover servers boot up, we start getting calls about servers hard booting. This is because the live and test server have the same unique ID in the agent, and they are both reporting back as the same server.

To solve these problems, I wanted to write a script that stops and disables the services that we don’t want running during test failover. I also wanted the script to assign a designated IP configuration so the servers could find the domain controllers.

Here’s what I came up with so far. I have it running in Scheduled Tasks on Windows Startup. Because a new NIC has to be installed during boot up, I built a delay in to give it enough time to complete.

This isn’t working flawlessly yet, but I wanted to put it out there and see if anyone had some feedback or better ideas. Two of the problems I’m having are as follows:

1. The script isn’t working consistently. This may be related to execution time. I’m considering changing it to a service, and then possibly I can do some type of pause and loop to confirm the NIC fully loaded. Some servers seem to work like I expect, and some seem to only work after I reboot them a second time.

2. Not all the services are stopping and being disabled. I can’t understand why, since it works for almost all the services. Sometimes the service is disabled but running, which is why I put a reboot in as the last action. Sometimes, a service will be stopped but not set to disabled, which means it will be running after the reboot.

Testing this is a pain. Everything seems to work when I have it on a test machine and run it manually. It even seems to work when I schedule it. The problem is the startup doesn’t have the same process it does when you are going from a development server to the failed over virtual server. To test it in the correct scenario, I have to update the script, copy it to the live server, and then wait for the live server to back up and replicate offsite. That can take a decent amount of time.

Anyway, let me know if you see any major amateur mistakes or better ways to do something.