Thursday, February 24, 2011

Some PowerCLI examples

Note:  All of these examples assume that the script contains the line to
           connect to a esx/esxi host. The line should look like the following:
           Connect-VIServer ip_of_host//hostname -user root -password xxxxx

---

Example # 1:  Power on all of the virtual machines

1. Use notepad to create a script on the windows machine with powercli
    installed. Call the script poweronallvms.ps1

2. Add the following line so that the script contains the following:
    Get-VM | Where-Object {$_.PowerState -eq "PoweredOff"} | Start-Vm

3. Execute the script by typing ./poweronnallvms.ps1 and verify the results
    with the vsphere client or the cli/vcli.

 ---

Example # 2: Create a virtual machine from scratch

1. Create a script called createvm.ps1 with your favorite editor.

2. Add the following lines to the script:
    New-VM -Name Lubuntu -NumCPU 2 -memoryMB 1024 -Datastore \  
    Storage1 DiskStorageFormat Thin -GuestID ubuntuGuest
    New-CDDrive -VM Lubuntu -ISOPath [Storage1]/lubuntu10.10.iso \
    -StartConnected
    Start-VM Lubuntu

3. Execute the script by typing ./createvm.ps1 and verify the results with the
    vsphere client. In this case, the iso image had been copied to the  
    datastore ahead of time.

---

Example # 3: Get generic information about host, vms, storage and network

1. Create a script called getinformation.ps1

2. Add the following lines to the script:
    Get-VMHost
    Get-VM
    Get-Datastore
    Get-DataCenter
    Get-VirtualSwitch
    Get-VirtualPortGroup

3. Execute the script by typing ./getinformation.ps1 and observe the output.

 ---

Wednesday, February 9, 2011

How to configure iscsi from the cli in 4.1

Steps to follow:

Note: The esxi host uses the ip address 10.1.1.1 for its management network and 10.1.1.2 for iscsi. The iscsi server uses the ip address 10.1.1.3.

1. Create a new standard virtual switch
esxcfg-vswitch -a vSwitch1

2. Create a port group for ip storage
esxcfg-vswitch -A "Ip Storage" vSwitch1

3. Add a network card to the virtual switch
esxcfg-vswitch -L vmnic2 vSwitch1

4. Create a vmkernel port for ip storage with an ip address (10.1.1.2)
esxcfg-vmknic -a -i 10.1.1.2 -n 255.255.255.0 "Ip Storage"

5. Enable the iscsi driver
esxcfg-swiscsi -e

6. Verify that the driver has been enabled
esxcfg-swiscsi -q

7. Find the name of your iscsi hba
esxcfg-scsidevs -a (vmhba33 in this case)

8. Bind the vmkernel port to the port group and verify
esxcli swiscsi nic add -n vmk1 -d vmhba33
esxcli swiscsi nic list -d vmhba33

9. Discover the targets available from a particular server
vmkiscsi-tool -D -a -i 10.1.1.3 vmhba33

10. Use the esxcfg-rescan command to find the new devices
esxcfg-rescan vmhba33

Note:  You can now verify your results by either using the vsphere client or the cli