Archive

Archive for the ‘Scripting’ Category

Exchange 2010 how to allow unauthenticated email connections

January 6, 2011 Leave a comment

To allow application servers, printers or other systems to send emails internal and external through Exchange 2010, use the following commands. These commands setup a receive connector and allow anonymous connections through that receive connector.

Change Receiveconnector to a name that makes sense for your environment.
Bindings dictate the specific IP address on which the receiveconnector will listen.
RemoteIPranges define the sending IP address for the printers or application servers.
Server is the name of the HUB transport server that the recevie connector will be created on.

New-ReceiveConnector -Name “Receiveconnector” -usage Custom -Bindings ’192.168.1.1:25′ -RemoteIPRanges 192.168.1.10-192.168.30.11 -server Exchange -permissiongroups AnonymousUsers

Get-ReceiveConnector “Receiveconnector” | Add-ADPermission -User “NT AUTHORITY\ANONYMOUS LOGON” -ExtendedRights “ms-Exch-SMTP-Accept-Any-Recipient”

Categories: Exchange, Microsoft, Scripting

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*

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

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
}