More PowerCLI Work

Further to my previous post, I’ve been expanding on my PowerCLI scripts to form a more comprehensive automated deployment/configuration of ESXi, vCenter and virtual machines (although I’ve not reached the VM bit yet).  The vCenter and VM deployment/configuration phases will utilise CSV files to hold the relevant information and keep such sensitive details away from the script, which allows the script to be more visible whilst the CSV’s are kept secure.  By having a small set of CSV’s that contain detailed settings I hope to keep management and future changes simple as well as well as provide a controlled means of updating the live environment with changes into those CSV’s without the need to manually connect and apply.  I’m now thinking of taking out any hardening or general configuration actions and putting them into a CSV where they are called and applied, so again, only the CSV needs updating whilst the script remains simple and will perform the same function with whatever data is called.  I don’t have 3rd party deployment/automation tool at my disposal so presently, Excel/esxcli/PowerCLI/Kickstart is all I have available.

I’ve split the phases into separate scripts and used a simple menu script to call the relevant one as chosen by the admin.  The vCenter customisation script manages datacenter creation (if needed), cluster creation or reset to custom defaults, folder creation and vApp/Resource Pool creation/reset.  It will apply in-depth settings for objects such as clusters and vApps once they’ve been agreed.  There are some hardening requirements here also but these will be added later once scripted and probably already deployed into what will be a production vCenter.  The ESXi script I’ve already mentioned in the previous post, whilst the VM deployment script will deploy VM’s using a selection of templates and customisation profiles, into the intended cluster (of 3), custom folders/RP’s/vApps, add disks according to the requirements of the intended guest role (and provision as thin or TEZ) into the appropriate datastore, set CPU/RAM, set IP/Mask/GW/DNS and configure the required number of NICs into the appropriate portgroups.  The 4th script will just contain any PowerCLI cmdlets or ESX CLI commands to configure any VM’s already deployed as necessary, such as templates, which will then be used to build other VM’s and in theory, propagate the settings!

Scripts attached and I’d love PowerCLI guru’s to review and offer advice on how I could streamline or improve the scripts.  I’m a rookie to this so have probably written lines of code to achieve something a wizard could do in one line!ps-customesxi ps-menu ps-vcenter (renamed to .txt extension since WordPress wouldn’t let me attach .ps1 and I can’t be arsed to sort that out!).

One thought to “More PowerCLI Work”

  1. Hmm, just spotted something wrong in the folder processing part of ps-vcenter! There’s a rogue ‘If (-Not’ loop using ‘Get-VApp’ which will always run the enclosed anyway, and if the folder does already exist it’ll pass through to the last ‘Else’ routine…so rogue entries just need clearing out.

Leave a Reply

Your email address will not be published. Required fields are marked *