Archive

Archive for the ‘Powershell’ Category

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
}
}

Outlook 2003 connectivity issues with Exchange 2010

December 22, 2010 1 comment

Although this error message has multiple causes one I have seen recently is due to Exchange 2010’s Default Throttling Policy with Outlook 2003. You may notice this error occur when opening additional shared mailboxes or calendars from Outlook.

The connection to the Microsoft Exchange is unavailable. Outlook must be online or connected to complete this action.

Using this command you can see the number of current RPC connections for a user. By default Exchange 2010 Throttling Policy allows 20 RPC connections per user so if you start receving this error once you hit 20 connections you know the Throttling Policy is causing your problems.

Get-LogonStatistics -Identity “username” | fl applicationid

The current resolution options include creating a less restrictive throttling policy and applying it to the effected users. There are reports that Outlook 2003 establishes more RPC connections than Outlook 2007/2010 as they are more efficient with their connections.

New-ThrottlingPolicy –name NewPolicy

Set-ThrottlingPolicy –identity NewPolicy -RCAMaxConcurrency 100

(I have used 100 here but any figure above 20, the default, may assist you depending on how many connections the client is establishing)

Set-Mailbox –Identity “user” –ThrottlingPolicy NewPolicy

It’s important to restart the throttling and rpcclientaccess services once you have applied to new policy as without this the changes won’t apply.

Thanks to the follow blogs for helping to point the way on making throttling policy changes apply.

workinghardinit

pepeedu

In relation to working with Exchange 2010 and Outlook 2003 clients this is the article to read.

Categories: Exchange, Microsoft, Powershell

Exchange 2010 Bulk Mailbox moves

December 6, 2010 9 comments

Exchange and Powershell allows administrators much greater flexibility and the power to perform operations easily with one or two simple commands. The following commands are ones that I use to assist me in the bulk migration of mailboxes.

Firstly I create a Universal Distribution Group that contains the users whos mailboxes I want to move. There are plenty of ways to perform mailbox moves and using distribution groups is one.
In the following example the group “Mailboxes to be moved” was used and I was moving the mailboxes to the Mailbox Database “Database01”.

Get-DistributionGroupmember -identity “Mailboxes to be moved” | new-moverequest -TargetDatabase Database01

To watch the progress of these moves I use the following commands

get-moverequest

get-moverequeststatistics -moverequestqueue “Database01” | sort-object status,displayname,percentcomplete,totalmailboxsize

To view further information and to identify the cause of any failures I use the following command to output the full moverequest report to a text file on the c: drive.

get-moverequeststatistics -moverequestqueue “mailbox database” -includereport | fl | out-file c:\get-moverequeststatistics.txt

There are many more options available that I haven’t gone into here including allow bad items and batch names, refer to: http://technet.microsoft.com/en-us/library/dd351123.aspx

Categories: Exchange, Powershell, Scripting

vSphere powercli multipath policy script examples – updated

August 31, 2010 5 comments

#Shows the multipath policy for all LUN’s connected to all hosts in Cluster Primary
Get-Cluster Primary | Get-VMHost | Get-ScsiLun -LunType disk

#Shows the multipath policy for all LUN’s connected to host host4
Get-VMHost host4 | Get-ScsiLun -LunType disk

#Sets the multipath policy for all EMC LUN’s (naa.6006*) connected to all hosts in Cluster RV00 to roundrobin
Get-Cluster RV00 | Get-VMHost | Get-ScsiLun -CanonicalName “naa.6006*” | Set-ScsiLun -MultipathPolicy “roundrobin”

#Sets the multipath policy for all EMC LUN’s connected to host host4
Get-VMHost host4 | Get-ScsiLun -CanonicalName “naa.6006*” | Set-ScsiLun -MultipathPolicy “roundrobin”

# Output the CanonicalName for all the devices on Cluster Primary that are EMC type (naa.6006*)
Get-Cluster Primary | Get-VMHost | Get-ScsiLun -CanonicalName “naa.6006*” | fl -show CanonicalName | out-file c:\shared\naa-id.txt

# This is a script I have developed to connect to a Virtual Center server and set the mulitpathing policy for all datastores on all hosts in a Cluster to Round Robin. You will need to install PowerCLI and vSphereCLI (ebsure you check the path to esxcli in the script matches your installation directory), it will prompt you for the vCenter Server IP, credentials, a Cluster name and the root password for the ESX hosts.

#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 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)

#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 enable the use of non-optimised paths
foreach ($viHost in $vihosts){
write-Host Executing use 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 1 –device $lun”
& $esxcli –server $viHost –username $Username –password $Password nmp roundrobin setconfig –useANO 1 –device $lun
}
}

Categories: EMC, Powershell, 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
}