Archive

Archive for the ‘PowerCLI’ Category

VMware Storage Canonical Name or Device Identifiers

January 6, 2011 6 comments

Making this list to assist me in helping to identify the type of storage by the Canonical name or Device ID for VMware Clusters and hosts where there is more than one type of Storage.

EMC Clariion = naa.6006*
IBM FastT DS = naa.600a*
HP EVA = naa.6001*
NetApp FAS = naa.60a9*

Advertisements
Categories: EMC, IBM, PowerCLI, Scripting, VMware

VMware ESX Multipath scripts

December 24, 2010 4 comments

Sets all devices on all hosts in a Cluster to Round Robin and enables un optimised paths.  

#Variables
#ESX host username
$Username = “root”
#vSphere CLI esxcli.exe path
$esxcli = “C:\Program Files\VMware\VMware vSphere CLI\bin\esxcli.exe”
#Prompt for vCenter Server
$viServer = Read-Host “Enter vCenter server Name: ”
Connect-VIServer $viServer
#Prompt for vCenter Server Cluster
$viCluster = Read-Host “Enter vCenter Cluster: ”

#list of ESX and ESXi host to perform operation against
$vihosts = Get-Cluster $viCluster | Get-vmhost | sort Name | % {$_.Name}

#prompt user for username
$UsernameInput = Read-Host -AsSecureString:$true “Please enter your common username for ESX hosts”

#prompt user for password
$passwordInput = Read-Host -AsSecureString:$true “Please enter your common password for ESX hosts”

#convert secure password to normal string
$Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($passwordInput)
$Password = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)
[System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($Ptr)

#convert secure username to normal string
$Usr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($UsernameInput)
$Username = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Usr)
[System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($Usr)
#loop through array of hosts and set default SATP policy to RoundRobin
for($i = 0; $i -le $vihosts.length -1; $i++) {
write-Host Executing set default PSP for ALUA_CX to RR on $vihosts[$i]
#insert esxcli parameters at the very end of the statement below
& $esxcli –server $vihosts[$i] –username $Username –password $Password nmp satp setdefaultpsp –satp VMW_SATP_ALUA_CX –psp VMW_PSP_RR
}

#loop through array of hosts and set PSP policy to RoundRobin
foreach ($viHost in $vihosts)
{
write-Host Executing set policy RR per device on $viHost
$lunList = get-vmhost $viHost | get-scsilun -CanonicalName “*” | % {$_.CanonicalName}
foreach ($lun in $lunList)
{
write-Host Executing set policy RR per device on $lun
#could not find a way to store the params in a variable you must
#insert esxcli parameters at the very end of the statement below
#write-host “$esxcli –server $viHost –username $Username –password $Password nmp device setpolicy –psp VMW_PSP_RR –device $lun”
& $esxcli –server $viHost –username $Username –password $Password nmp device setpolicy –psp VMW_PSP_RR –device $lun
}
}

#loop through array of hosts and disable the use of non-optimised paths
foreach ($viHost in $vihosts){
write-Host Executing disable unoptimized paths on $viHost
foreach ($lun in $lunList){
#could not find a way to store the params in a variable you must
#insert esxcli parameters at the very end of the statement below
#write-host “$esxcli –server $viHost –username $Username –password $Password nmp roundrobin setconfig –useANO 0 –device $lun”
& $esxcli –server $viHost –username $Username –password $Password nmp roundrobin setconfig –useANO 0 –device $lun
}
}

VMware bulk vMotion via PowerCLI

December 17, 2010 Leave a comment

Unfortunately VMware licesning for Enterprise and Enterprise Plus is not cheap. Some of the customers I work with cannot afford this licensing so they get Advanced and miss out on DRS. One of my biggest issues with this is putting hosts into Maintenance mode, although the host will start entering maintenance mode it cannot automagically move all the VM’s off onto other hosts. I get around having to manaully migrate each VM I use the following script. It’s limited to moving all the VM’s from one host to one other host, enjoy!

Get-VM -Location (Get-VMHost ‘sourcehostname’) | Move-VM -Destination (GetVM-Host ‘destinationhostname’)

PowerCLI rocks!

http://www.vmware.com/support/developer/windowstoolkit/wintk40/doc/viwin_admg.pdf

Categories: PowerCLI, Scripting, VMware

Scripting esxcli commands

August 12, 2010 1 comment

Update Dec 2010

Refer to this and this post for example scripts for setting the mutlipath policies of ESX devices (datastores).

Also PowerCLI 4.1 now offers direct experienmental support for esxcli from within PowerCLI.

http://blogs.vmware.com/vipowershell/2010/12/esxcli-now-available-through-powercli.html

—————————

I wanted to script the ESX configuration of multipath policies for specific devices. I found that powercli could do the mulitpath policy as per the following command:

Get-Cluster “clustername” | Get-VMHost | Get-ScsiLun -CanonicalName “naa.6006*” | Set-ScsiLun -MultipathPolicy “roundrobin”

naa.6006 is EMC storage, this site has EMC and HP storage but I was only modifying the EMC path policies.

But the esxcli command to disable unoptimized paths wasn’t available with powercli:

esxcli nmp roundrobin setconfig –useANO 0 –device naa.60060160e8802900e7414c361ba4df11

Using the following powershell script from William Liam as the basis I was able to produce a script which can run multiple esxcli commands against multiple hosts, perfect!

http://www.virtuallyghetto.com/2010/06/esxcli-part3-automating-esxcli-using.html

Example:

$Username = “root”
$esxcli = “C:\Program Files\VMware\VMware vSphere CLI\bin\esxcli.exe”
#$Params = “nmp roundrobin setconfig –useANO 1 –device naa.60060160e880290005445743c3a5df11”

#list of ESX and ESXi host to perform operation against
$vihosts = @(“host1″,”host2″,”host3”)

#prompt user for password
$passwordInput = Read-Host -AsSecureString:$true “Please enter your common password for hosts”

#convert secure password to normal string
$Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($passwordInput)
$Password = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)
[System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($Ptr)

#loop through array of hosts
for($i = 0; $i -le $vihosts.length -1; $i++) {
write-Host Executing set default PSP for ALUA_CX to RR on $vihosts[$i]
#could not find a way to store the params in a variable you must
#insert esxcli parameters at the very end of the statement below
$esxcli –server $vihosts[$i] –username $Username –password $Password nmp satp setdefaultpsp –satp VMW_SATP_ALUA_CX –psp VMW_PSP_RR
}

#loop through array of hosts
for($i = 0; $i -le $vihosts.length -1; $i++) {
write-Host Executing set policy RR per device on $vihosts[$i]
#could not find a way to store the params in a variable you must
#insert esxcli parameters at the very end of the statement below
$esxcli –server $vihosts[$i] –username $Username –password $Password nmp device setpolicy –psp VMW_PSP_RR –device naa.60060160e880290005445743c3a5df11
$esxcli –server $vihosts[$i] –username $Username –password $Password nmp device setpolicy –psp VMW_PSP_RR –device naa.60060160e8802900bdb0f3eb16a4df11
$esxcli –server $vihosts[$i] –username $Username –password $Password nmp device setpolicy –psp VMW_PSP_RR –device naa.60060160e8802900c178f2bbc3a5df11
}

#loop through array of hosts
for($i = 0; $i -le $vihosts.length -1; $i++) {
write-Host Executing use unoptimized paths on $vihosts[$i]
#could not find a way to store the params in a variable you must
#insert esxcli parameters at the very end of the statement below
$esxcli –server $vihosts[$i] –username $Username –password $Password nmp roundrobin setconfig –useANO 1 –device naa.60060160e880290005445743c3a5df11
$esxcli –server $vihosts[$i] –username $Username –password $Password nmp roundrobin setconfig –useANO 1 –device naa.60060160e8802900bdb0f3eb16a4df11
$esxcli –server $vihosts[$i] –username $Username –password $Password nmp roundrobin setconfig –useANO 1 –device naa.60060160e8802900c178f2bbc3a5df11
}