Tag: PowerCLI

As part of my efforts to automate further within the private cloud environment at work, setting up a home lab and studying for the VCAP-DCA exam, I have been working on a PowerCLI script to configure vCenter once it is deployed. (Note: we are also working on deploying vCenter itself using Puppet, but that’s another post).

It has been really good to work through the functionality exposed through PowerCLI (Version 5.8 Release 1) and those only exposed through the API. I would also like to note that @vBrianGraf from VMware Tech Marketing has been an awesome resource for several different pieces that are not currently exposed directly through PowerCLI.

The goals for the script were as follows:

  1. Setup Datacenter and Folder management.
  2. Create cluster(s) with High Availability and DRS configured.
    1. HA would set the HA Admission Control Policy to reserver 25% of CPU and Memory.
  3. Create vDS and default portgroup.
  4. Setup Autodeploy.
    1. For the Intel NUC, this included adding a custom VIB for the e1001 network driver.

The script can be downloaded here and seen after the break.

(more…)

Read More

I am preparing for my VCAP-DCA exam and having to automate more and more of my daily tasks within our VMware environment at work — as a result, I am using PowerCLI constantly. As I result, I thought I would share a couple quick and dirty little scripts that I have had to use lately.

Mileage will vary, but they’ve proven useful for me at work (some variables values have been edited).

Changing Network Label

> $i = 1
> $VLAN = "VLAN1012"
> while ($i -le 20) {
> $VMName = "prefix" + $i + ".site"
> Get-VM -Name $VMName | Get-NetworkAdapter | Set-NetworkAdapter -Portgroup $VLAN -Confirm:$false | Out-Null
> $i++
> }
>

Deleting and Adding a New Disk

> $i = 1
> while ($i -le 20) {
> $VMName = "prefix" + $i + ".site"
> Get-HardDisk -VM $VMName | Remove-HardDisk -Confirm:$false | Out-Null
> New-HardDisk -VM $VMName -CapacityGB 525 -Datastore "DRSCluster1" -Confirm:$false | Out-Null
> $i++
> }
>

Changing Allocated RAM

> $i = 1
> while ($i -le 20) {
> $VMName = "prefix" + $i + ".site"
> Set-VM -VM $VMName -MemoryGB 32 -Confirm:$false | Out-Null
> $i++
> }
>

Read More

Encountered an issue with Auto Deploy this week where it wasn’t properly assigning the VMware License key contained within the Host Profile, so the ESXi hosts would not add themselves into the vCenter environment automatically. Looking into the issue, we only have this problem when we try to have Auto Deploy add in HP blade servers using the VSAN license key for this environment.

Anyway, it became necessary to add the hosts in manually after they each PXE booted into ESXi and apply the proper license key. From there, because we are doing everything through the slower web client for VSAN, we were going to have to apply the host profile to 80 hosts and there was no way I wanted to do that manually.

So I wrote up a quick script to handle this for us. Feel free to reuse if you find it helpful.

[string]$VCENTER = ""
[string]$USER = "administrator@vsphere.local"
[string]$PASSWD = ""
[string]$HOSTPROFILE = "vCache"

Connect-VIServer $VCENTER -User $USER -Password $PASSWORD

$i = 100
while ($i -le 120) {
  $hostname = "mraesxi" + $i " ".local.domain"
  Set-VMHost -VMHost $hostname -State "Maintenance" -Confirm:$false
  Apply-VMHostProfile -Entity $hostname -Profile $HOSTPROFILE -Confirm:$false
  Set-VMHost -VMHost $hostname -State "Connected" -Confirm:$false
  $i++
}

The script itself could likely be more efficient, especially around putting everything into maintenance mode and then apply the host profile to all the virtual machines in a parallel fashion. This was a quick hack to get around an issue we were dealing with while trying to bring online a bunch of blade chassis’ at once.

Read More