Write-Host "This script will modify the policy of all your shared LUNs on all ESX Servers" -ForegroundColor CyanWrite-Host "in a Cluster to Fixed and select a preferred path in a round-robin fashion." -ForegroundColor Cyan#if ($args.Length -lt 2) {Write-Host "usage: -c or -s "exit 1} else {if ($args[0] -eq "-c") { $VMHosts = Get-Cluster $args[1] | Get-VMHost }if ($args[0] -eq "-s") { $VMHosts = Get-VMHost $args[1] }}Write-Host "Modifiying ESX hosts:" $VMHostsforeach ($VMHost in $VMHosts){$luns = $VMHost|get-scsilun -luntype disk| where-object {$_.ConsoleDeviceName -like "/vmfs/devices/disks/vml*"}| Where-object {$_.CanonicalName -notlike "vmhba32*"} |Sort-Object CanonicalName$firstLUNPaths = Get-ScsiLunPath $luns[0]$numPaths = $firstLUNPaths.Length$count = 0foreach ($lun in $luns){"count : $count""numpath : $numPaths"$lun.CanonicalNameif ($count -ge $numPaths) { $count = 0 }$paths = Get-ScsiLunPath -ScsiLun $lun$paths$lun|Set-ScsiLun -MultipathPolicy Fixed -PreferredPath $paths[$count]$count += 1# Sleep for some seconds as some arrays dont like doing this too fast. and with running vm's its .....Start-Sleep -Seconds 3}}
Thursday, September 10, 2009
Powershell ESX Lun Balance script
Tuesday, February 10, 2009
ESX iscsi enable script using vi-toolkit.
Param ($VMhost = "")I used this for setting the same settings for all my hosts and ensuring that they all are 100% alike.
$iscsiHba = "vmhba32"
$iscsiServer = "Iscsi-SAN-IP"
$iscsiPort = 3260
$target = New-Object VMware.Vim.HostInternetScsiHBASendTarget
$target.address = $iscsiServer
$target.port = $iscsiPort
$iscsiauthprop = New-Object VMware.Vim.HostInternetScsiHbaAuthenticationProperties
#$iscsiauthprop.ChapAuthEnabled = "true"
#$iscsiauthprop.ChapName = "Chapuser"
#$iscsiauthprop.ChapSecret = "ChapSecret"
$h = Get-VMHost $VMhost
Foreach ($hostView in ( Get-View -VIObject $h)) {
$storageSystem = Get-View $hostView.configManager.storageSystem
# Enable software iSCSI controller
$storageSystem.UpdateSoftwareInternetScsiEnabled($true)
# Add iSCSI Server for dynamic discovery
$storageSystem.AddInternetScsiSendTargets($iscsiHba, $target)
$storageSystem.UpdateInternetScsiAuthenticationProperties($iscsiHba,$iscsiauthprop)
# Scan for iSCSI devices
$storageSystem.RescanHba($iscsiHba)
}
Friday, October 17, 2008
List vm usage and assosiated datastore
$datastoreExp = @{N="Datastore"; E={ ($_ | get-datastore | select-object -first 1).Name }}$diskSizeExp = @{N="Total Disk"; E={ ($_ | get-harddisk | measure-object -property CapacityKB -sum).Sum }}get-vm | select Name, $datastoreExp, $diskSizeExp | sort -property Datastore,"Total Disk"
Thursday, September 18, 2008
Updating tools on VM's in Vmware
$VmList = Get-VM | Where-Object {$_.Powerstate -eq "PoweredON"} | % { Get-View $_.ID } | where {$_.guest.toolsstatus -notmatch "Ok"} | Select Name
foreach ($vm in $VmList) {
"Updating :" $vm
Update-Tools $vm
}
Monday, July 28, 2008
Disable and Turn Off IPv6 Support in Vista
IPv6 (Internet Protocol version 6) is the successor for IPv4, the current version of most popular network layer protocol for packet-switched internetworks used on the Internet. In Windows Vista, IPv6 is fully implemented and supported, is also installed and enabled by default, with full Internet Protocol security (IPsec) support for IPv6 traffic and Teredo tunneling support for non-IPv6 aware devices.
IPv6 is not common yet, as most software, routers, modems, and other network equipments does not support the emerging and future-proof protocol yet. Beside, turning off IPv6 support does not affect the functionality of Internet browsing for average users. Thus IPv6 and/or Teredo can and (quite likely) should be disabled if it's not in use to conserve system resources. Unlike Windows XP, IPv6 in Windows Vista cannot be uninstalled, according to Microsoft. However, IPv6 can be disabled. The following guide will allow users to disable IPv6 on a specific connection of a network interface card.
- Go to Network Connections folder (click on Start button, then right click on Network, select Properties, then click on "Manager network connections" on Tasks pane).
- You should see various LAN, wireless, Bluetooth, high speed Internet, and other network connections available on the Vista computer with the network adapter description. Right click on the network connection that you want to disable the IPv6 interface and select "Properties".
Click "Continue" on User Access Control permission request prompt.
- Clear the check box next to the Internet Protocol version 6 (TCP/IPv6) component in the list under "This connection uses the following items" box.
- Click OK when done.
- To re-enable IPv6, tick back the check box.
This method disables IPv6 on the particular LAN interface and connection. For other network adapter or connection, users have to repeat the steps to disable IPv6. Beside, disable IPv6 also does not disable IPv6 on tunnel interfaces or the IPv6 loopback interface.
It's also possible to disable IPv6 and/or Teredo via Vista system registry. The registry settings also allow users to selectively disable components and configure behaviors for IPv6 in Windows Vista.
- Open Registry Editor (regedit).
- Navigate to the following registry key branch:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\
Services\tcpip6\Parameters\ - Create the following registry value (DWORD type):
DisabledComponents
Note that the name must be exactly as shown, including capitalization. DisabledComponents is set to 0 by default.
- The DisabledComponents registry value is a bit mask that controls the following series of flags, starting with the low order bit (Bit 0). To determine the value of DisabledComponents for a specific set of bits, the process is complicated, were hexadecimal value is calculated from binary number of the bits in correct position. For convenient, the following table lists some common configuration combinations and the corresponding DWORD value of DisabledComponents.
Configuration combination DisabledComponents value Disable all tunnel interfaces 0×1 Disable 6to4 0×2 Disable ISATAP 0×4 Disable Teredo 0×8 Disable Teredo and 6to4 0xA Disable all LAN and PPP interfaces 0×10 Disable all LAN, PPP, and tunnel interfaces 0×11 Prefer IPv4 over IPv6 0×20 Disable IPv6 over all interfaces and prefer IPv4 to IPv6 0xFF As seen from table above, to disable IPv6 support globally on all interface, set the value data for DisabledComponents to 000000FF, or simply FF. The registry entry will look like below:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters]
"DisabledComponents"=dword:000000ff - Restart the computer for changes to take effect.
- To revert and enable IPv6, delete "DisabledComponents" registry key or set its registry value to 0.
Tuesday, July 22, 2008
Sending mail from Esx 3.x servers
tar zxfv MIME-Lite-3.01.tar.gzcd MIME-Lite-3.01perl Makefile.PLmake testmake install
Saturday, June 21, 2008
ESX LUN Load balance
# by Allan Christiansen/2008 on esx 3.5.0 Update 1#for PATHS in 2 4 6 8 10 12 14 16doSTPATHS=${PATHS}COUNTER=${RANDOM}while [[ ${COUNTER} -gt ${PATHS} ]];doCOUNT=`expr ${COUNTER} / ${PATHS}`COUNTER=${COUNT}donefor LUN in $(esxcfg-mpath -l | grep "Disk" | grep "has ${STPATHS} paths" | awk '{print $2}')doesxcfg-mpath --lun=${LUN} --path=$(esxcfg-mpath -q --lun=${LUN} | grep FC | awk '{print $4}' | awk '{print NR "S\t " $0}' | grep ${COUNTER}S | awk '{print $2}') --preferredCOUNT=`expr ${COUNTER} + 1`COUNTER=${COUNT}if [[ ${COUNTER} -gt ${STPATHS} ]]thenCOUNTER="1"fidonedone