1 2 Previous Next 29 Replies Latest reply on Jan 21, 2009 3:07 PM by lberc

    How To: Configure freshly booted ESX with PowerShell

    Enthusiast

      As part of a larger project I've been working on a set of scripts which configure a freshly-installed ESX (or ESXi) system into Virtual Center (after first attempting to remove previous VC state and clean state from the host).  Currently they follow a typical post-boot configuration pattern:

       

      1. Set ESX password

      2. Add to Virtual Center cluster

      3. Configure Virtual Switches

      4. Configure Port Groups

      5. Add NFS partitions

      6. Add iSCSI partitions

      7. Configure NTP

      8. Configure VMotion

      Before trying, modify esx-master.ps1 and esx-profile.ps1 to local conditions (or your password will be set to "CHANGEME").

       

      Command: esx-autoconfigure.ps1 "hostname|ip-address"

       

      As this is my initial foray into PowerShell, please excuse any idiosyncracies.

       

       

      This is a work-in-progress - feedback welcome.  Points awarded for the best suggestions in the next few days.

       

       

       

       

      lance

       

       

      (2008-Sep-02 - I've moved the script files to ESX Automated Configuration Midwife)

        • 1. Re: How To: Configure freshly booted ESX with PowerShell
          halr9000 Master

          My comments are as follows:

           

          1. http://www.vmware.com/landing_pages/toolkit_contest.html

          2. Cool,   I've been working on something similar for a project at work (not to mention for my book).

          3. I'm a judge for #1, so I'll refrain from commenting directly on your code in case you decide to submit it, which I suggest you do.

           

           

          Author of the upcoming book: Managing VMware Infrastructure with PowerShell

          Co-Host, PowerScripting Podcast (http://powerscripting.net)

          1 person found this helpful
          • 2. Re: How To: Configure freshly booted ESX with PowerShell
            LucD Guru
            Community WarriorsUser ModeratorsvExpert

            Some suggestions:

            - configure or check DNS and gateways before steps 3/4/7/8. Critical for clustering, HA and DRS!

            - configure the firewall

            - (eventually) configure some advanced ESX settings. See for example a recent discussion about NFS.MaxVolumes

            - check (and eventually configure) licensing before using clustering with HA/DRS/vMotion

            - configure (or adjust) resource pool(s). Adding an ESX server will increase the available resources.

            • 3. Re: How To: Configure freshly booted ESX with PowerShell
              alanrenouf Master
              VMware Employees

               

              Very nice, you should definately enter the comp.

               

               

               

              Alan Renouf

              VMware, Citrix, Microsoft Consultant

              UK

               

               

              My Blog

               

               

              • 4. Re: How To: Configure freshly booted ESX with PowerShell
                olan025 Enthusiast

                iberc,

                 

                I'm doing a large roll-out of esxi. I have been working on the exact same as what you're doing. If I can add anything across what you got i may post it.

                 

                 

                You're scripts look to be more portable. This is my first dive into significant scripting not to mention powershell. The envronment i'm building for is very homogenous so the work reflects it. this is definately work in progress. these files on their own need to be edited etc and linked.

                 

                 

                I've been looking for awhile now for configuration of ESXi via powershell and it seems very limited.  Most resources are directed at management of existing.

                 

                Message was edited by: olan025

                • 5. Re: How To: Configure freshly booted ESX with PowerShell
                  Master

                   

                  Lance works for VMware, no $5000 for him, for us 3rd prize is we're fired

                  • 6. Re: How To: Configure freshly booted ESX with PowerShell
                    Enthusiast

                    My cover has been blown. - l

                    • 7. Re: How To: Configure freshly booted ESX with PowerShell
                      depping Champion
                      User ModeratorsVMware Employees

                      Looks great!

                       

                      Lance, do you know Aiden Dalgleish? He's a PSO Consultant from the UK and already created a hell of a lot scripts for installing. Talk to him, he's got some cool stuff!

                       

                       

                       

                       

                      Duncan

                      My virtualisation blog:

                      http://www.yellow-bricks.com

                       

                      If you find this information useful, please award points for "correct" or "helpful".

                      • 8. Re: How To: Configure freshly booted ESX with PowerShell
                        olan025 Enthusiast

                         

                        Hal,

                         

                         

                        How about making an exception to allow me a sneak peak at your new book? My scripting needs to be tuned up as you can tell i'm a beginner if you looked at my earlier attachments.

                         

                         

                         

                         

                         

                        I'm making changes and updates to those, if anyone does care for them post it. otherwise my stuff is pretty basic compared to Lance's functionalized code.

                         

                         

                        • 9. Re: How To: Configure freshly booted ESX with PowerShell
                          olan025 Enthusiast

                          Updated and named to be different than the other here.

                           

                           

                           

                           

                           

                           

                          • recent - I have a newer version that takes hosts from a CSV file. This eliminates the need to create a hostname.ps1 for each server. when you get over 90 servers those files are unmanageable, and any changes made to the template means a rebuild of them.... So I now use a CSV.

                           

                          I'm thinking of rearchitecting it again... if there's any interest i'll look at posting it. I have to de customize if for the job i'm doing here to post it which is some extra work....

                           

                           

                          Unpublished updates.

                           

                           

                          - fixed NTP auto start and DNS Search Suffix- Thanks LucD

                           

                           

                          - added blat email option to email log or report

                           

                           

                          - added csv function for hosts to replace having individual host-template.ps1 files for each host.

                           

                           

                          - fixed a few minor issues

                          • 10. Re: How To: Configure freshly booted ESX with PowerShell
                            LeeTheMC Novice

                             

                            I am able to configure the NTP Servers (as many of you have done in your scripts), but how do I check the "NTP Client Enabled" checkbox?  I presume that this is required to tell the ESX server to use the NTP servers configured.  Thanks in advance.

                             

                             

                            Lee

                             

                             

                            • 11. Re: How To: Configure freshly booted ESX with PowerShell
                              LucD Guru
                              User ModeratorsvExpertCommunity Warriors

                              You could use the Set-VMHostService cmdlet.

                              Set-VMHostService -HostService (Get-VMHostservice -VMHost (Get-VMHost esx1.test.local) | Where-Object {$_.key -eq "ntpd"}) -policy "automatic"
                              

                               

                              A bit of a cryptic command I admit, but it seems to work.

                              For -policy you can use "on", "off" or "automatic"

                              1 person found this helpful
                              • 12. Re: How To: Configure freshly booted ESX with PowerShell
                                Enthusiast

                                My ESXi hosts run NTP when I configure the server addresses without having to explicitly enable the service, but LucD's command should work if necessary.

                                • 13. Re: How To: Configure freshly booted ESX with PowerShell
                                  SCampbell Hot Shot

                                  Has anyone succeeded in configuring the license server and edition on an ESX server using Powershell?

                                   

                                  I am about to embark on using the Java sample in the SDK to try to do it. I have also looked at the C++ code posted in the community.

                                   

                                  Thanks

                                   

                                  Update2: Sep 23. This is extracted from code that I believe is working properly, even though are likely more efficient ways. Some of these are used for other aspects of my provisioning script so there may be more than you need. Note in particular the use of the $ESXHostView.MoRef. -- Start of rant -- It cost an hour of head scratching and random guesses and finally get-member to find that. Sure would be nice to have some documentation of the VMware.VIM .Net Classes. (Hint. Hint.) Note that cmdlet help and that SDK website don't count for newbie PS/VIM people who need to access the .Net libraries. The .Net libraries help is a good start with its 5 classes. I think we need to see the same thing for all the "real" classes too. Of course, maybe it's all there, and I haven't been able to find it. If so, please accept my apologies. -- End of rant --

                                   

                                  $LicenseServer="27000@myVCS.myDomain.local"

                                  $HostPassword=Read-Host "Enter the password to the root account on the ESX Host" -asSecureString

                                  $ESXConnect=Connect-VIServer -Server $HostIP -User $HostUser `

                                  -Password (\[System.Runtime.InteropServices.Marshal\]::PtrToStringAuto( `

                                  \[System.Runtime.InteropServices.Marshal\]::SecureStringToBSTR($HostPassword))) `

                                  -ErrorAction Inquire

                                  $ESXHost=Get-VMHost -Name $HostFQDN

                                  $ESXHostView=$ESXHost | Get-View

                                  $ServiceInstance=Get-View -Server $ESXConnect ServiceInstance

                                  $LicManRef=$ServiceInstance.Content.LicenseManager

                                  $LicManView=Get-View -Server $ESXConnect $LicManRef

                                  $LicServerSource=New-Object VMWARE.VIM.LicenseServerSource

                                  $LicServerSource.LicenseServer=$LicenseServer

                                  $LicManView.SetLicenseEdition($ESXHostView.MoRef,"esxFull")

                                  $LicManView.ConfigureLicenseSource($ESXHostView.MoRef,$LicServerSource)

                                  • 14. Re: How To: Configure freshly booted ESX with PowerShell
                                    halr9000 Master

                                    This:

                                    $HostView=Get-View -Viewtype HostSystem -Filter @{"Name"=($HostName + "." + $HostPath)}

                                     

                                    Can simply be replaced by:

                                    $HostView = Get-VMHost $HostName | Get-View

                                     

                                    Otherwise, looks ok but I haven't tested it.  I have an aversion to messing around with licensing ever since a bad 48 hours when I downed some production terminal servers several years ago. 

                                     






                                    Author of the upcoming book: Managing VMware Infrastructure with PowerShell

                                    Co-Host, PowerScripting Podcast (http://powerscripting.net)

                                    1 2 Previous Next