Caution: Articles written for technical not grammatical accuracy, If poor grammar offends you proceed with caution ;-)
Last week my boss came to me and asked if I could write a script for a customer to register VM’s after being replicated from once VI environment to another. I agreed to take on the project and go for it.
Like everything I do these days I decided to use powershell to write the script. I have taken a liking to it and the fact that I can run the scripts on both ESX and ESXi hosts saves me from having to re-create scripts all the time. So I plugged away to 3am wrote the script, tested it inside out and sideways in my lab. I was confident in the scripts ability to register all vm’s form all datastores I went ahead and sent it off to the customer.
A few days later I was on a conference call with the customer. They were having problems with the script. It wasn’t registering all the vm’s. After a few hours of troubleshooting I realized that I needed to go back and try to recreate the problem’s in my lab to fix the script, but the customer didn’t have that kind of time.
A short while after getting off the meeting with the customer I received an email from them stating not to worry they had gotten a shell script that worked. Then I started to think……. I went in to my lab and created a shell script that would do the job. The shell script was 5 lines long as oppose to powershell script that is about 40 lines.
The shell script if anyone needs it looks like this:
for v in ‘find /vmfs/volumes/ -name “*.vmx” `
echo “Registering $v” >> /log/registeredvms.log
vmware-cmd -s register $v
So the short of the story is sometimes it is best to keep it simple stupid. Utilizing powershell for this problem was just too much overkill and in the end there were issues that were overlooked that I still can’t reproduce in my lab. A simple shell script is all that was required and what I should have originally decided on.
So in the end this is a lesson learned and hopefully it will prevent someone else from making the same mistake.