back to article Want to deploy virtual machines in a hurry? PowerShell is your friend

Sometimes you just need to do things fast. Being able to deploy new virtual machines rapidly is a necessity when you are prototyping proof of concepts, running virtual desktop deployments or when you just need to roll out new virtual machines in a lab environment. Let’s face it, unless you have written PowerShell scripts to …

  1. Electron Shepherd

    Some Questions

    For us mere mortals without enterprise MS agreements, what are the licensing implications of just starting multiple copies of Office and so on?

    Are the GIs activated already?

    You mention GIs that have updates installed. How do you keep them updated as new patches are released on Patch Tuesday?

    1. Forty Two

      Re: Some Questions

      Short answer - jail time.

      I may be doing it wrong as I am fairly new to VM's or perhaps there is a better way but you will need volume license key or whatever they call it this year for office and windows. I activate the "golden image" and the deployed machines are good to go. No good answer for updates other than to deploy the image, do updates and immediately make a new image. Even if not completely up to date it is still a timesaver as deploying a 2008R2 machine ( /shame, yes we still do ) from the original .iso is at least an hour of updating so having an image that is only a month or 3 behind is a real help. But yes, keeping images up to date with updates is a chore.

      Be aware that having the volume key and an activated machine vs. the actual number of machines legally licensed to use are two different things. At least for us in .edu

      Eagerly await better answers from people more clever than myself.

    2. Anonymous Coward
      Anonymous Coward

      PowerShell is a step backwards

      The whole point of a GUI is to simplify management. PowerShell is becoming more and more prevalent and undermining the Windows GUI. If I click the wrong box on a GUI I can unclick it before applying. With PowerShell if you make a mistake on entry it sticks and can do lots of damage. A former employee of mine wiped out 72 email accounts with a single PS entry.

      If the purists want PowerShell, that's fine. But make sure I can still do my entire job via GUI as well. Sometimes I don't want to change 230 accounts all at once.

      1. Electron Shepherd

        Re: PowerShell is a step backwards

        If I click the wrong box on a GUI I can unclick it before applying. With PowerShell if you make a mistake on entry it sticks and can do lots of damage.

        And if I highlight a folder on a network share and press the Delete key, potentially a vast amount of data is deleted, and can't be recovered without using the backups - no different to your 72 email accounts.

        Just because the interface is graphical rather than command-line doesn't in any way prevent careless wholesale destruction of data.

      2. Lyndon Hills 1

        Re: PowerShell is a step backwards

        The whole point is that if you need to do the same thing repeatedly, having a script means that you won't accidently 'check the wrong box'. Nor for that matter will your PFY.

  2. Forty Two

    Really ?

    Good and informative article.

    However, regarding "Once you have got it going, you will wonder why you ever did it any other way.".

    I believe I will stick to Vcenter's "deploy VM from template" /click /click {machinename} /click /click /click /smoke break while it builds. (done).

    That license fee does not seem so expensive now.

    That Azure destination command may be the longest cli command I have seen. Good info for scripting as I would not wish to try that manually twice in a row on a Monday.

    1. EddieD

      Re: Really ?

      "That Azure destination command may be the longest cli command I have seen. Good info for scripting as I would not wish to try that manually twice in a row on a Monday."

      Type it out once (or copy/paste from the recipe supplied by the nice man), using nice wee tokens for volatile information then wrap it up in a nice wee perl script e.g. azuredeploy.pl --token1 --token2 --token3....etc

      Edit: Other text/string manipulation languages exist...I just stick with the one I sort of know...

      1. Fuzz

        Re: Really ?

        I love the idea that you wrap a powershell script in perl, do you call that from a batch file wrapped in python?

    2. Anonymous Coward
      Anonymous Coward

      Re: Really ?

      "I believe I will stick to Vcenter's "deploy VM from template" /click /click {machinename} /click /click /click /smoke break while it builds. (done)."

      You can do the same from SCVM. No need to spend $6K just for a console...

  3. DanDanDan

    Obligatory...

    http://xkcd.com/1319/

    http://xkcd.com/1205/

  4. Steve Button Silver badge

    So, basically what RightScale does... but with a lot more work.

    How quaint. :-P

    1. Electron Shepherd

      Or to put it another way...

      A free way of doing something RightScale charges you for.

  5. John 104

    ;)

    Windows Server 2012 has PowerShell remoting enabled by default, but if you are running 2008r2 then you will need to Google how to enable it manually.

    Let me google that for you...

    http://lmgtfy.com/?q=https%3A%2F%2Ftechnet.microsoft.com%2Fen-us%2Flibrary%2Fhh849694.aspx

    Nice write up. I might suggest for future episodes to tag your PS code in a different color for ease of reading.

    Have you tried using PSExec to remotely run your post deploy scripts? I haven't, just curious.

    I like to wrap certain bits of code in scripts that I can run repeatedly vs copy paste each time I need it.

    The "switch" ($option) function is great for this:

    -------------------------------------------------------------------------------------------------------------------------------------------

    # Write path options to console

    Write-Host "Enter Number to Select Option"

    write-host

    Write-Host "1. Option 1"

    Write-Host "2. Option 2"

    Write-Host "3. Option N+"

    Write-Host "X. Other"

    write-host

    # Option Selection

    $Option = Read-Host -Prompt "Select Path From List Above"

    switch ($Path)

    {

    1 {$Option="Image 1"}

    2 {$Option="Image 2"}

    3 {$Option="Image N+"}

    8 {$Option= Read-Host -Prompt "Your Text Here"}

    default {$Option="Whatever"} # Use this as a default deploy or catch it as an error and exit.

    }

    $ImageOptoin = $Option

    --------------------------------------------------------------------------------------------------------------------------------------

    You can add/remove as many options as you like. Then when you are ready to deploy your VMs, just fire up this script and pick the one you want. You should be able to add in any other parameters that you desire further down in the script once you have selected your machine type. Just use if else statements to capture the option name and run with it.

  6. John 104

    Scripting FTW

    For those of you poo pooing this, shame on you. The whole point of scripting, in any language and on any platform, is to remove or reduce the possibility for human error. VMWare or Azure/Hyper-V GUI is great, but you can just as easily screw something up by checking the wrong box and clicking OK. The best practice is to do just that....practice. In a lab. Away from your production systems. Figure it out, then move it to prod. I guess they don't teach that in IT 101 these days...

    /rant

  7. SecretSonOfHG

    Can you explain why you prefer everything to be PowerShell?

    I understand the author's preference for having everything in PowerShell, but it strucks to me that the Copy-Item PS construction (for example) looks a lot more verbose than a plain old copy command?

  8. CAPS LOCK

    Shouldn't this be marked as an advert...

    Justsayin'.....

  9. MissingSecurity

    Why don't I use PS more?

    Modules ... and that "You need to be on this product, by this time, in this dimension, by this date ..." licensing/ support model.

    For instance, I was planning on writing a PS script to setup Win2K servers. All the basic stuff, Computer Name, Setting Updates, Remote access, etc. I prefer to write them on my Laptop (Win 7 Pro) (and sadly on my own time). Ignoring the long naming conventions (not that bad considering I like understanding whats going on), I wanted to get/set IP Address.

    Set-NetIPAddress seems reasonable right?

    Minus its a module that is not supported in Win 7. Why I don't know, but i can get it if upgrade to Win8 (Can I give a bigger middle finger?) or I can do this strictly on Win2K Server, but that kinda of defeats the purpose of writing it on one system and testing it on the other.

    To be fair, I can still write this out on the Win 7 box, but it just needs to be executed from the proper environment, BUT WHY? I never run into this shit with Python and I can cross platform that shit. I don't get all the pretty toys, but I love tools to make my life easier, I JUST WANT THE TOOL KIT INCLUDED.

    1. Anonymous Coward
      Anonymous Coward

      Re: Why don't I use PS more?

      "it just needs to be executed from the proper environment, BUT WHY?"

      Win2K is approaching 15 years old now and does not fully support newer PowerShell versions and some functions now exposed in newer Windows OSs. For full PowerShell capabilities use a current Windows OS version: PowerShell 5 is in late preview and was first released a year ago:

      http://blogs.msdn.com/b/powershell/archive/2015/02/18/windows-management-framework-5-0-preview-february-2015-is-now-available.aspx

  10. batfastad

    PowersHELL!

    PowerShell is no doubt a step on from the abysmal effort at command line that MS had been peddling since the mid-90s. Admittedly I've only looked at it briefly but the implementation and syntax of commands that I've used seems so inconsistent and appears to vary massively depending on the Windows team/product (Exchange vs IIS vs SQL Server etc).

    It's useful as a way of exposing a programmatic API to what is usually point-n-click Windows interfaces and wizards.

    But you still need a decent wrapper language to bind it all together. And that's where cygwin comes in for me ;)

    Not hatin', just sayin'.

    1. Anonymous Coward
      Anonymous Coward

      Re: PowersHELL!

      "PowerShell is no doubt a step on from the abysmal effort at command line that MS had been peddling since the mid-90s."

      It's sort of like hybrid Bash shells that include Perl, but even more advanced.

      "But you still need a decent wrapper language to bind it all together. And that's where cygwin comes in for me ;)"

      No you don't - Powershell can do branching and PROPER parallel execution. . Using Cygwin is like wrapping it in a batch file. Pointless. Powershell is ahead of anything I have used to date in the *Nix world.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Other stories you might like