VMware

This Question is Answered

1 2 Previous Next 29 Replies Last post: Jan 21, 2009 3:07 PM by lberc  

How To: Configure freshly booted ESX with PowerShell posted: Sep 2, 2008 3:50 PM

Click to view lberc's profile Enthusiast 26 posts since
Sep 1, 2006
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)

Click to view halr9000's profile Master 813 posts since
Jun 7, 2007
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)

Click to view LucD's profile Champion 2,430 posts since
Oct 31, 2005
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.
Click to view alanrenouf's profile Master 582 posts since
Feb 28, 2006

Very nice, you should definately enter the comp.


Alan Renouf
VMware, Citrix, Microsoft Consultant
UK

My Blog

Click to view olan025's profile Enthusiast 48 posts since
Jan 22, 2007
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

Attachments:
Click to view c_shanklin's profile Master 754 posts since
Dec 3, 2007

Lance works for VMware, no $5000 for him, for us 3rd prize is we're fired :(
Click to view depping's profile Champion 2,997 posts since
Jan 17, 2005
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".

Click to view olan025's profile Enthusiast 48 posts since
Jan 22, 2007

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.

Click to view olan025's profile Enthusiast 48 posts since
Jan 22, 2007
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
Attachments:
Click to view LeeTheMC's profile Novice 9 posts since
Sep 2, 2008

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

Click to view LucD's profile Champion 2,430 posts since
Oct 31, 2005
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"
Click to view SCampbell's profile Enthusiast 106 posts since
Apr 18, 2005
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)
Click to view halr9000's profile Master 813 posts since
Jun 7, 2007
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)

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities