This is a great video around PowerCLI and a must watch
ProfessionalVMware BrownBag – PowerCLI 101 w/ Glenn Sizemore from ProfessionalVMware on Vimeo.
Thanks goes to Glenn Sizemore and ProfessionalVMware for some great content
By Paul Wood
This is a great video around PowerCLI and a must watch
ProfessionalVMware BrownBag – PowerCLI 101 w/ Glenn Sizemore from ProfessionalVMware on Vimeo.
Thanks goes to Glenn Sizemore and ProfessionalVMware for some great content
By Paul Wood
Today I have added a new page to my site. This page is a resource hub for the VCAP study and will be updated as and when. I’m using this for my own study but please feel free to comment on updated information that needs to be change.
By Paul Wood
During the initial setup on first boot of the vMA the configuration screen will ask questions regarding to ip address and hostname. If during this process an error has been made it is possible run the initial setup again.
I had this very issue as by mistake I selected "yes" to using DHCP. I spent some time looking at conf files but then found a reply on the VMWare forums that had the answer.
Go to the console screen of the vMA which will if it has just restarted prompting for a password to be set. Once this is complete follow the steps listed below:
This will come up with some rather comical text and the vi-admin password will need to be entered again. Once this has been entered the initial setup will run again allowing for any errors to be corrected.
By Paul Wood
I came across this issue as I run my LAB as stated before on a laptop which means I cannot run x64 virtual machines on my ESX installations. After a quick search I came across a post by Kenneth van Ditmarsch which took me through the exact problem and below is the fix that I have tried and tested.
I have edited the two lines that need to be changed due to the "" that had been used. If the original version had been copied and pasted then the file would not work and the virtual machine fail.
After importing the new vSphere Management Assistant (vMA) 4.1 on my VMware Workstation 7 environment I noticed that it the virtual machine boots with a memory crash error. The error is “unable to access resume device” message and eventually ends with a kernel panic screen shown below.
The memory crash error can be ignored after checking CentOS blogs. The reason why the vMA virtual machine is hanging is due to the fact that its SCSI card and OS type needs to be changed in the .vmx file
Follow the steps below (credits to Justin for pointing this out to me!)
scsi0.virtualDev = "lsilogic"
guestOS = "rhel5-64"
Once the vMA has booted succesfully the configuration screen will be see. At this point follow vSphere Management Assistant Guide which will advise on how the vMA should be setup.
By Paul Wood
This blog will carry on from part 2 adding more simple functionality to the LAB being created.
In this blog we will look at adding iSCSI storage to the LAB through PowerCLi. To do this the LAB will need storage of which many are available on the internet (this can be real or virtual). The script is designed to allow the addition of a datastore with a specific ip address and name. This has not been tested in a situation where multiple iSCSI targets could reply.
This is not as hard as it may seem and with the aid of using a script every host can be configured with the same datastore in one simple script. Scripts take away human error and misconfiguration making the life of an administrator that much easier. The vSphere PowerCLI Administration Guide is a great place to start for simple scripts to help in the day to day operation of a virtual infrastructure. The following has its base taken from this guide but converted to allow the configuration of all the hosts through one script.
Below is the complete script which I will break down underneath.
<br />
$hosts = Get-VMHost<br />
$name = $hosts</p>
<p>Foreach ($name in $hosts) {<br />
Get-VMHostStorage $name | Set-VMHostStorage -SoftwareIScsiEnabled $true<br />
$iscsiHba = Get-VMHostHba -Type iScsi<br />
$iscsiHba | New-IScsiHbaTarget -Address 10.10.1.10 -Type Send<br />
Get-VMHostStorage $name -RescanAllHba<br />
$lunPath = Get-ScsiLun -VMHost $name -CanonicalName ($iscsiHba.Device + "*") | Get-ScsiLunPath<br />
New-Datastore -Vmfs -VMHost $name -Path $lunpath.LunPath -Name iSCSI<br />
}<br />
At the start the following two lines are carried out. This gets all the hosts that are managed by the current virtual center and stores them in $host. This information is then stored in $name to be used during the rest of the script
<br /> $hosts = Get-VMHost<br /> $name = $hosts<br />
As we want this script to run against every host that is stored in $name a Foreach is being used. This allows the script to run through each host until each is completed. The next line is retrieving the host storages on the host and then enabling the iSCSI adapter
<br /> Get-VMHostStorage $name | Set-VMHostStorage -SoftwareIScsiEnabled $true<br />
The next reads in the HBA data but only for iSCSI and stores it in $iscsiHba
<br /> $iscsiHba = Get-VMHostHba -Type iScsi<br />
The $iscsiHba information is then used in the following line to setup a new dynamic target with a specific ip address (using the default 3260 port. If another is needed then add –Port xxxx)
<br /> $iscsiHba | New-IScsiHbaTarget -Address 10.10.1.10 -Type Send<br />
The HBA needs to be rescanned now as it would if this was being done manually so the next line does exactly that
<br /> Get-VMHostStorage $name -RescanAllHba<br />
The next line is getting the canonical name of the iSCSi lun and storing this information in $lunPath
<br /> $lunPath = Get-ScsiLun -VMHost $name -CanonicalName ($iscsiHba.Device + "*") | Get-ScsiLunPath<br />
The last line adds the datastore that has been found during the above process. It will add a Vmfs file system to a host using the canonical name the previous line obtained and give the datastore a name if iSCSI (If the datastore with the name specified already exists then this datastore is just added to the host and can be used. I have not tested with a datastore that is not formatted to confirm that it would be formatted, named and added)
<br /> New-Datastore -Vmfs -VMHost $name -Path $lunpath.LunPath -Name iSCSI<br />
By Paul Wood
This blog will carry on from part 1 adding more simple functionality to the LAB being created.
The LAB has not changed since part 1 so I will not list the contents again. Please refer back to part 1 for this information.
The following will be added to the LAB in this blog:
To start with we will configure a couple of NTP servers (No need to change the firewall on ESXi).
I will assume that a connection to the VC through PowerCLi has been established.
Please follow the simple instructions below:
#
#adds two ntp servers and then restarts the ntpd service
#
Add-VmHostNtpServer -NtpServer "ntp1.sandvika.net" -VMHost (Get-VMHost) -Confirm:$false
Add-VmHostNtpServer -NtpServer "ntp2d.mcc.ac.uk" -VMHost (Get-VMHost) -Confirm:$false
$ntpd = Get-VMHostService -VMHost (Get-VMHost) | where {$_.Key -eq 'ntpd'}
Restart-VMHostService $ntpd -Confirm:$false
# #configures a single host vSwitch0 to have two vmnic for resilience # $vswitch = Get-VirtualSwitch -VMHost labnode1.lab.local -Name vSwitch0 Set-VirtualSwitch -VirtualSwitch $vswitch -Nic vmnic0, vmnic2 -Confirm:$false
Note: In the above code a single host is being interrogated and only the vSwitch called vSwitch0 is being checked. It is better to specify using –Name
#
#configures all hosts' vSwithc0 to have two vmnic for resilience
#
$hosts = Get-VMHost
$name = $hosts
Foreach ($name in $hosts)
{
$vswitch = Get-VirtualSwitch -VMHost $name -Name vSwitch0
Set-VirtualSwitch -VirtualSwitch $vswitch -Nic vmnic0, vmnic2 -Confirm:$false
}
Note In the above code I have made the code work for us. It is now reading in all the host and then passing this on to an ‘Foreach’ statement so changing all the host’s in a few lines.
#
#creates a new switch called vSwitch1 and then adds 4 vmnic for all host's
#
$hosts = Get-VMHost
$name = $hosts
Foreach ($name in $hosts)
{
New-VirtualSwitch -VMHost $name -Name vSwitch1
$vswitch = Get-VirtualSwitch -VMHost $name -Name vSwitch1
Set-VirtualSwitch -VirtualSwitch $vswitch -Nic vmnic1, vmnic3, vmnic4, vmnic5 -Confirm:$false
}
#
#removes the 'VM Network' portgroup then creates a new one on a different switch
#
$hosts = Get-VMHost
$name = $hosts
Foreach ($name in $hosts)
{
$vswitch = Get-VirtualSwitch -VMHost $name -Name vSwitch1
$pg = Get-VirtualPortgroup -VMHost $name -Name 'VM Network'
Remove-VirtualPortgroup -VirtualPortgroup $pg -Confirm:$false
$nvmpg = New-VirtualPortGroup -VirtualSwitch $vswitch -Name 'VM Network'
}
#
#for all hosts this script reads a csv file for vMotion information. This information is then used to add a vMotion portgroup to vSwitch0 adding ip, subnet and then enabling. Once that is complete the gateway is also added
#The location of the .CSV file. This can be local or on a share
#
$getinfo = Import-Csv <a href="file://\\server\share\information.csv">\\server\share\information.csv</a>
$getinfo | % {
$Type = $_.Type #!!!! Case Sensitive !!!!!!
$gethost = Get-VMHost -Name $_.HostName
$name = $gethosts
$PortGroup = $_.PortGroupName
$IP = $_.IP
$Subnet = $_.Subnet
$kernelGW = $_.KernelGW
#Creates vMotion switch and configures vmkernel gateway (located under DNS and Routing in configuration tab)
Foreach ($name in $gethost) {
IF ($Type -eq "vMotion") {
$vswitch = Get-VirtualSwitch -VMHost $name -Name vSwitch0
$vmotion = New-VirtualPortGroup -VirtualSwitch $vswitch -Name $PortGroup
New-VMHostNetworkAdapter -VMHost $name -PortGroup $PortGroup -VirtualSwitch $vswitch -IP $IP -SubnetMask $subnet -VMotionEnabled: $true
$vmhostnetwork = get-vmhostnetwork $gethost
set-vmhostnetwork -network $vmhostnetwork -vmkernelgateway $kernelGW
}
}
}
This is all for now and I hope it has helped understand in simple examples how powerful PowerCLi is to anyone who needs to manage many hosts. I will cover in the next blog how to add storage amongst other things.
By Paul Wood
Updated
I run Windows 7 x64 and the issue I had is when installing the latest PowerCLi the command box flashes on the screen and then disappears. It seems the issue is related to the target line in the shortcut that is used to launch PowerCLi.
Below is the original line from the installation shortcut with the bold being what causes the issue:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -psc “C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1″ -noe -c “. \”C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-VIToolkitEnvironment.ps1\”"
Below is what the line should be changed to again with the text in bold that has been change:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noe -c “Add-PSSnapin VMware.VimAutomation.Core; . \”C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\”"
Once the line has been changed PowerCLi will launch and open without issue. All that is needed then is to set the signed scripts to run which is done by running the following command at the prompt:
set-executionpolicy remotesigned
Select ‘yes’ and type exit
Open PowerCLi again and you will be prompted with a fully functioning PowerCLi installation to start working with.
By Paul Wood
This blog will take you through creating a simple LAB but expects that the following is setup:
The configuration I run my LAB in is as follows:
Note: The reason for the memory on the ESXi host being set to this memory configuration is so that HA can be setup and configured
I will be setting up the LAB with the following names:
Below are the commands to create a datacenter, cluster and join the hosts to the cluster enabling HA etc.
Note: The result is pipelined to the fl command to retrieve a flat view of the new datacenter properties and displayed on the screen
Note: It used to be that DrsMode was used but this has been replaced with DrsAutomationLevel.
Note: This needs to be done for each host that is to be connected to the cluster in the LAB. It is also possible to connect the host via ip but as I’m using Active Directory the name is being used. This process may take some time as HA will be setup when the host’s join the cluster due to the configuration specified
This can be of course made into a very simple PowerCLi script that can be run from the PowerCLi command prompt. Below is the complete script that can be copied and then edited to work in your environment.
##################################### ## ## Created by Paul Wood on 21/03/2011 ## ## This script will connect to the vCenter server creating a new datacenter, cluster and then joining 2 hosts ## The script will need to be edited with your specific information ## ##################################### Connect-VIServer servername –username username -password password New-Datacenter -Location Datacenters -Name LAB | fl New-Cluster -Location LAB -Name Surrey -DRSEnabled -DrsAutomationLevel FullyAutomated -HAEnabled –HAAdmissionControlEnabled | fl Add-VMHost labnode1.lab.local -Location Surrey -User root -Password password | fl Add-VMHost labnode2.lab.local -Location Surrey -User root -Password password | fl