tsignal_vmwareesx_180x300_animated
Badges

vexpert_logo_100x57

gestaltitbadge

follow-me-twitter

Subscribe to me on FriendFeed

Advertisements
Comments / DISQUS
Feedjit.com

PowerShell Scripting Examples for VMware Virtual Infrastructure

Like a lot of virtual infrastructure administrators already seem to be doing, I decided I better start learning about PowerShell scripting for VMware ESX and VirtualCenter. There has been a lot written on this topic in the recent months, but I have been just been speed reading through with the idea that “I’ll get around to understanding and learning this later when I have more time”. Now I am holding myself to this promise, so this post is my first steps to making myself learn. I am also looking forward to attending the Scripting VMware Infrastructure: Automating, Integrating, and Extending VI VMWorld Hands On Lab (Lab 09) already on my schedule for the conference.

Here’s what little I know about Powershell for VMware so far:

Here are links to several useful PowerShell scripts created by the user community:

baeke.info :: PowerShell script to check ESX patch status

“You can use the simple PowerShell script below to check ESX server patching status from your Windows client.”

VMware Powershell script - remove connected iso

“… is a script which can remove the connected iso files from the CD drive. Some administrators do not disconnect a CD drive when the have finished use the ISO, the side effects of this behavior are: the VM regularly polls the CD drive which creates a slight overhead and a VMotion may fail. This script can run unattended e.g. every night so even when an ISO file remains mounted it is ejected every night.”

Adding and re-adding ESX servers to VirtualCenter

“This script automatically detects any disconnected host and reconnects it (be sure you connect to VirtualCenter before running it though!) On the first line, the script also allows setting a password Sometimes you can’t reconnect a host without a password, usually because the password has been changed. If this applies to you, set the password here and you’ll be re-connecting hosts faster than ever.”

[omitted]

If an ESX host you want to manage doesn’t appear in VirtualCenter, you need to add it. This is a bit tricker than reconnecting since there’s no inventory in VirtualCenter to tell you the IP addresses of all the hosts you use, and you also need to know a host’s password in order to add it. This is another case where entering things in a spreadsheet can really speed things up. I made just such a spreadsheet, and here’s a video of me using it.”

PowerShell Script for VDI Mass Replicas

“Folks, many folks have asked HOW we do the “thousands of desktops, instantly, consuming the space of one” that I demoed and described about here.

Here are the step-by-step instructions and PowerShell scripts we use.”

Automatically Configure VirtualCenter Virtual Networking Using PowerShell

“I wrote a little PowerShell script that goes out to a VirtualCenter instance and grabs a list of all the Port Groups in use by every ESX host under VC management. It ignores the default ‘VM Network’, ‘Service Console’, and ‘VMKernel’ PortGroups. Then it goes out to each ESX host under management and makes sure that it has all of the VLans and that they are using the correct VLanId. It does some simple error checking. If the VLan ID’s don’t match up, the script prompts you to ask you to pick the right one. So now when I need to add a network, I can just add it to any host under management and then run my script to reconcile everything. I think its neat. Saves me time and human error.”

Scripting VMware ESX servers to fail over to other ESX servers

“The solution used in this article gets by the downtime limitation by using VMware Converter 3.0.1 Enterprise to schedule a “conversion” of the target virtual machine to a new location on another ESX server while the target virtual machine is still running.

VMware Converter 3.0.1 Enterprise allows you to use a tool called p2vtool.exe. This is a command-line interface for VMware Converter 3.0.1. It should be noted that there is only experimental support for p2vtool.exe. However, I have tested the scripted conversion presented in this article several times with no failures.”

Related Posts

Tags: , , , ,

  • Kevin
    What is all the fuss about with powershell? I can do the same things with perl, and don't have to do it from a windoze box.
  • A friend of mine, Glenn, has posted several powershell examples to www.get-admin.com.

    @Kevin, I agree, but not everyone is comfortable with perl. There's a lot of windows admins, who are also ESX admins, and if they feel more comfortable with powershell, then what does it hurt?
  • Andrew,

    Thanks for the link

    Kevin,

    I know as little about scripting with Perl as I do with PowerShell, but I know I am more likely to use a Windows OS to script at work then a Linux OS. Judging by their track record so far, VMware has come to the same conclusions for the majority of their customers.
  • I think the big appeal of PowerShell is the fact that it is being positioned as *the* scripting language for the future of the Windows OS. I was very surprised to find even the Microsoft Press "Windows Command Line Pocket Consultant" had a healthy dose of PowerShell in it. I almost feel like I have no choice but to learn it. :)

    Rich - if you're looking for a good Powershell book to start with, I found the Powershell Cookbook from O'Reilly has been a good read, with alot of practical examples on common OS tasks. I started from scratch on PowerShell with this book.

    I think we are going to see a good amount of new Powershell Scripts coming out of the VMware Powershell contest they are holding.
  • Jason,

    Thanks for the book recommendation. I can't wait to see what comes out the contest as well!
  • James
    Variation on the patch check script...but with my 2 cents....don't really think it's all too secure to be putting your password in a plain text powershell script file...

    http://www.p2vd.com/?p=143

    *8)
blog comments powered by Disqus
h9_coolvendor_160x600
@rbrambley tweets
Advertisements
VMTN Roundtable Podcasts
Subscribe



Add to Google Reader or Homepage
Subscribe in NewsGator Online
Add to netvibes
Add to Plusmo

UserOnline