mercoledì 31 luglio 2013

VMware: Deploy VMs from Template using PowerCLI

After yesterday's introductive post, today I would like to share a simple, yet powerful, PowerCLI script that allows you to deploy VMs from a Template.

This is the script structure:

 1..<N> | Foreach {  
 New-VM -vmhost <ESX_HOST> -Name <VM_NAME> -Template <TEMPLATE> -Datastore <DATASTORE> [-OtherOptions]  
 }  

Where:

<N> is the number of VMs you need to deploy.
<ESX_HOST> is the host where you will deploy your VMs
<TEMPLATE> is the template from which your VMs will be created
<DATASTORE> is the datastore that will contain your VMs
[-OtherOptions] are additional options that can be used in conjunction with New-VM command.

As you can see it's really basic, but New-VM cmdlet is really powerful and it has a lot of options. To go through all on New-VM options:


Get-Help New-VM -Detailed


Here's how I used it today for deploying 6 VMs that will be Oracle RAC nodes.


Open a text editor and paste this code in it saving file with .ps1 extension.

 1..2 | Foreach {  
 New-VM -vmhost esx1.testdomain.com -Name RAC$_ -Template OL6 -Datastore datastore1  
 }  
 3..4 | Foreach {  
 New-VM -vmhost esx2.testdomain.com -Name RAC$_ -Template OL6 -Datastore datastore2 -ResourcePool TestResourcePool  
 }  
 5..6 | Foreach {  
 New-VM -vmhost esx3.testdomain.com -Name RAC$_ -Template OL6 -Datastore datastore3 | Start-VM  
 }  



As you can see we are deploying 6 VMs, named RAC1 to RAC6 from a template called OL6.
RAC1 and RAC2 will be deployed on host esx1.testdomain.com, RAC3 and RAC4 on host esx2.testdomain.com and RAC5 and RAC6 on host esx3.testdomain.com.
RAC3 and RAC4 will be placed in a resource pool called TestResourcePool.
RAC5 and RAC6 will be powered on after deployment due to Start-VM cmdlet.


To run this simple script just open VMware vSphere PowerCLI, connect to your vCenter (or host) using Connect-VIServer cmdlet as stated in VMware: vSphere PowerCLI 101 post.


A progress bar will appear in your PowerCLI console


That's all!!Happy VMware Automation!!

martedì 30 luglio 2013

VMware: vSphere PowerCLI 101

These days I'm speding some time learning VMware vSphere PowerCLI. I think vSphere PowerCLI is a great tool for automating tasks among vSphere environments. It's so useful to automate repetitive tasks, it allows IT admins to save huge amounts of time performing common tasks using scripts.

To start using VMware vSphere PowerCLI simply go here:

vSphere PowerCLI: Windows PowerShell interface for managing vSphere

You need to download and install VMware vSphere PowerCLI on your Windows machine in order to start scripting.

Here is the official vSphere PowerCLI Documentation

Another really useful PowerCLI document to read is Getting Started with PowerCLI 4.1 – Automating Your vSphere Environment  which contains a lot of useful commands to perform basic tasks.

Last link I would like to share is the VMware PowerCLI 5.1 Poster which presents all PowerCLI cmdlets in a single panel grouping them by function (Network Operations, Logs/Reporting, etc.)

So, let's start with PowerCLI 101 post...

Connecting/Disconnecting to vCenter Server:

To start using PowerCLI you need to connect to a vCenter Server or to an ESXi host

Connect-VIServer -Server <VCENTER_IP_ADDRESS> -User <USERNAME> -Password <PASSWORD>


Example: Connect-VIServer -Server 192.168.116.155 -User root -Password vmware

To disconnect:

Disconnect-VIServer


Available Commands:

To list all available commands:

Get-Command

Example: Get-Command *VM*  -> To list all commands containing word "VM" in their name.

To get more infos on a command

Get-Help <COMMAND_NAME> -Detailed


Selecting Columns:

<cmdlet> | Select-Object <COLUMNS_TO_SHOW>

Example: Get-VM | Select-Object Name, PowerState -> To display only name and power state of every VM


Prevent truncated columns:

If a column contains many data it could happen that output it's truncated. To prevent this:

<cmdlet> | Select-Object <COLUMNS_TO_SHOW> | Ft -autosize


Redirecting Output:

<cmdlet> > <OUTPUT_FILE>

Example: Get-VM > C:\List_of_VMs.txt -> To create a file named "List_of_VMs.txt" which contains the list of all our VMs


Exporting CSVs:

<cmdlet> | Export-Csv <OUTPUT_FILE>

Example: Get-VM | Export-Csv C:\List_of_VMs.csv -> To export to CSV infos about VMs


Combining Cmdlets:

<cmdlet> | <cmdlet>

Example:  Get-VMHost esx1.testdomain.com | Get-VM -> To show all VMs running on esx1.testdomain.com host


Nested Expressions:

<cmdlet> | Select-Object @{N="<COLUMN_NAME>"; E={<EXPRESSION>}}

Example:  Get-VM | Select-Object Name, @{N="Datastore"; E={$_ | Get-Datastore}} -> Display VM name and datastore on which each VM resides

In the next post I will provide some PowerCLI useful scripts.

That's all!!

lunedì 29 luglio 2013

ESXi: The operation is not allowed in the current state

Today I stepped into this issue while trying to vMotion a VM to another host. When validating destination host this error is displayed:

The operation is not allowed in the current state

After a brief search I found KB 1003829 which states:

1)Cancel the Enter maintenance mode
My host was not entering maintenance mode

2)Restart the ESX host's management agents
Done but still got error

3)Wait until any pending tasks for the ESX host are complete
No running tasks reported from vSphere Client. Logged into my host using SSH to see if there are pending tasks using this command:

vim-cmd vimsvc/task_list

# vim-cmd vimsvc/task_list
(ManagedObjectReference) [
   'vim.Task:haTask-5-vim...'
]

There was a task still running due to the command above (if there are no ongoing tasks the brackets "[]" are empty), waited until completion but vMotion host validation still failed with message "The operation is not allowed in the current state".

4.a)Disconnect and then reconnect the ESX host to VirtualCenter
Done but still got error

4.b)Restart the VMware VirtualCenter Server service
Finally here is how I solved my issue!

To restart vCenter Server go to:

https://YOUR_VCENTER_SERVER:5480

Click Stop button and wait until services stopping occurs.





Then cick Start and wait for completion.


After this I was able to correctly vMotion guest VMs!!

giovedì 25 luglio 2013

VMware: This system is not a supported platform

I encountered this error while installing HP branded Windows 2008 OEM on VMware ESXi 5.1.


This error occurs due to the check Windows performs to verify it is being installed on a HP branded machine.

Anyway this can be easily solved as stated in Installation of Microsoft Software Products Sold by HP (as OEM) on Virtual Machines Is Now Supported

Poweroff your VM, right click on it, choose Edit Settings -> Options and click Configuration Parameters


Now click Add Row and insert:

Name -> SMBIOS.reflectHost 

Value -> TRUE

as depicted in image below:


Click OK and poweron VM. This time you will be able to install Windows 2008 OEM correctly.

If you prefer you can manually edit the .vmx file of your virtual machine, using a text editor, adding a new line:

SMBIOS.reflectHost = TRUE

That's all!!

mercoledì 17 luglio 2013

Oracle UCM: DisableNtfs8dot3

If you have ever installed an instance of Oracle WebCenter Content on a Windows server you probably stepped into this error:


The weblayout directory is on a filesystem with 8dot3 semantics. Legacy 16-bit 8dot3 filenames conflict with revision labels and will cause file loss. Disable 8dot3 semantics by running "Installer DisableNtfs8dot3" and then restarting Windows.




This can be solved in two ways:

1)Using Oracle suggested procedure

This is done running Installer.exe with DisableNtfs8dot3 parameter.

To do this open command prompt (Start -> Run -> cmd) and go to:


<DomainHome>\ucm\cs\bin\Installer.exe DisableNtfs8dot3


In my server it was:


E:\Oracle\Middleware\user_projects\domains\ecm_domain\ucm\cs\bin\Installer.exe DisableNtfs8dot3


2)Editing a registry key

Open regedit (Start -> Run -> regedit) and go to:

HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/FileSystem

Edit NtfsDisable8dot3NameCreation key and change its value to 1 (default value is 2).


After this restart UCM instance (if you edit registry also a server reboot would be necessary) and alert message will disappear.

That's all!!