Server Superstar Training – PowerShell lesson

I had a conversation yesterday with an IT Pro about PowerShell, scripting and their environment (all running Hyper-V).  If there is something you are going to do once or twice – do you really need to script/automate it?  It’s up to you (and/or your company) – a script can be documented and tracked (as opposed to other changes – I know a lot of situations where someone made changes but has no trail of what those changes were).

What is a good example of something that I change regularly on my servers?  I have a demo environment that sometimes should be only internal connectivity and sometimes I want the virtual machines to have wired network access.  In PowerShell, I can change the VM’s network adapter setting with the following:

Connect-VMNetworkAdapter -vmname DRSERVER2 -switch EXTWired

Connect-VMNetworkAdapter -vmname DRSERVER2 -switch INTonly

The EXTWired and INTonly are virtual switches I setup in Hyper-V and this is a perfect example of something I could automate, but once the virtual switches are setup, I don’t make a lot of changes to them.  I could write PowerShell to create the virtual switches as well as assign them to a virtual machine’s network adapter, but the thing that I’m constantly changing is just the virtual switch the VMs are attached to (probably multiple times a day depending on what I’m demoing/testing).

In a future post, we will discuss modifications to this script so that the virtual machine (DRSERVER2) is a variable, how to enumerate all the virtual machines setup on a Hyper-V host, and other examples of using PowerShell.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s