If you are a Windows administrator and have recently taken over VMware vSphere 4, it is a pleasure to know that you are familiar with and love the PowerShell platform to manage the VMware environment.
In contrast to the general view, VMware is used to help administrators complete their work, although Microsoft's technology is involved in theft when necessary. Go to PowerCLI and set PowerCLI for ease of use. The installation is based on the existing Windows PowerCLI installation.
Windows administrators often ask whether they need to learn Linux. My answer to this is that you should really forget about learning Linux and ESX control commands. Not only is the value of those technologies reduced once ESXi becomes VMware standard, but also because ESX control does not provide many commands. On the contrary, there are hundreds of instruction sets in PowerCLI, which provide a certain degree of functionality and unavailability control in the Console environment.
Let's take a look at some of the most important uses of PowerCLI.
Use PowerCLI to create a data center
The best examples of the value of PowerCLI are the instruction sets that allow you to create objects in vCenter, which I keep using When disassembling, resetting, and recreating my lab platform, but they can also be used to expand a new virtual data center.
Once vCenter is installed, your main task is to create a data center, cluster, and resource pool. If you are pursuing consistency and automation, you can use PowerCLI to do everything. To create a new data center, you need to connect to the relevant vCenterConnect-VISServer), and then use this new data center command to create a data center object.
The first part of the PowerCLI script only connects to vCenter through one management account, and the second part creates a variable called "$ root" to set a location for the data center, if the get folder command runs together with non-recursive conversion, the location of the new data center will be set at the top of the vCenter tree. As shown below, using the new data center command and the-name variable to set their names is a simple process for UpTown, MidTown, and DownTown, my three data centers.
connect-viservervcnyc.corp –username corp\administrator –passwordPassword1$root = Get-Folder –NoRecursionnew-datacenter –location $root -name ‘NYC DataCenter - UpTown'new-datacenter –location $root -name ‘NYC DataCenter - MidTown’new-datacenter –location $root -name ‘NYC DataCenter - DownTown'
The following shows the results of each command.
Figure 1. Use PowerCLI to upload a Data Center Object
Use PowerCLI to create a cluster
Of course, the next thing you want to do is to create a VWware cluster in each of your data centers. This can be done through the new cluster commands, these commands support many options to help you easily configure the cluster's VMware high-availability HA) and distributed resource center DRS ). In the following PowerCLI script, I created a Cluster named "Cluster" in "NYC DataCenter-Downtown, this clever thing is actually added through the following additional parameters:
new-cluster –location (get-datacenter –name 'NYC DataCenter – DownTown') -name 'Cluster' -HAEnabled -HAAdmissionControlEnabled –HAFailoverLevel 2-DRSEnabled –DRSMode PartiallyAutomated
Therefore, you can use-HAEnabled to activate the HA and DRS technologies of VMware on the cluster and set-HAFailover level to 2, which indicates that before the VM becomes unavailable, I can afford a maximum of 2 ESX hosts. This is a simple method to ensure that the system is not overloaded when a considerable number of hosts fail.
DRS mode parameters provide three options: semi-automatic, automatic, and manual. For example, when a VM is started, the semi-automatic option allows the cluster to determine which ESX host the VM runs on. Keep in mind that the Administrator will still receive a notification saying that when DRS will consider it a good idea to move the VM and basically control the single sector on the main DRS section of the cluster mobile dialog box.
Figure 2. Automatic level set by VM Cluster
Use PowerCLI to create a resource pool
Maybe the next phase will be to define the resource pool on the VMware cluster. As you know, the VMware resource pool is a way to collect large resources of VMware clusters and divide them into easy management units. It is common to create a resource pool for each application type, such as the Active Directory domain controller and SQL Server. You can use the new-resourcepool command to automate the operation. Just like other commands we use, you also need to set the location parameter and create the name of the resource pool. Repeat this process to create all the required resource pools.
new-resourcepool –location (get-datacenter –name 'NYC DataCenter - DownTown' | get-cluster –name 'Cluster') -name ‘Web Servers’new-resourcepool –location (get-datacenter –name 'NYC DataCenter - DownTown' | get-cluster –name 'Cluster') -name ‘Database Servers’
It is interesting to use PowerCLI in this way that before creating a resource pool, you usually add the required ESX host to the cluster, however, with PowerCLI, you can create your resource pool before adding an ESX host. The following is a good example of how PowerCLI executes tasks that are usually rejected by vSphere clients.
Figure 3. Use PowerCLI to create a resource pool
Add an ESX host through PowerCLI
The administrator needs to execute a major task to add the ESX host to the cluster. This can be done through the add-vmhostcmdlet command in PowerCLI.
add-vmhost esx1.corp.com -location (get-datacenter –name 'NYC DataCenter- DownTown'| get-cluster–name 'Cluster') -user root –password Password1 -force
By using the get-datacenter and get-cluster commands together, we can explicitly specify an object in vCenter as the correct location where the ESX host will be added to the directory. Adding them to the HA cluster also triggers the startup of the HA proxy to the ESX host.
Here, the-force parameter is used to receive the default SSL certificate generated during the installation of the ESX host. If the-force parameter is not available, in order to successfully Add the ESX host to the vCenter, you need to fully trust the SSL Certificate; otherwise, the task will fail and an error message is displayed, "because you are using a self-Signed SSL Certificate, the authentication of the specified host authorization is invalid."
Figure 4. Add an ESX host to the Cluster
As you can see, PowerCLI is very powerful and Its value lies in its ability to easily perform tasks automatically. If you have mastered the basics of Windows PowerShell, it is easier to learn to add commands in VMware.
Year after year, VMware has added more commands to make daily management work and life easier, but if you want to, you can go further than those commands. PowerCLI can be used in combination with the VMware SDK through a network server engine. In this way, all the tasks you execute on the vSphere client can be automatically executed using PowerCLI through the SDK. The new PowerCLI version released by VMware allows you to use a simple command to access the required configuration options. However, before that, the above method was a good choice.
Original article: http://www.searchsv.com.cn/showcontent_44985.htm