SQL : Database ‘Database_Name’ already exists

SQL : Database ‘Database_Name’ already exists

When re-attaching a database I received an error “Database ‘Database_Name’ already exists.” There were no duplicate name databases with the instance, so this was incorrect.

After running the following SQL I found that the database was still ‘known:’
select name from sys.databases

To resolve the issue, execute the command below, changingt he database name:
DROP database ‘Database_Name’

vSphere : PowerCLI Create New VM

vSphere : PowerCLI Create New VM

The script below will semi-automate the creation of a new VM. Change the items in red to suit your environment.

$vmhost = Get-VMHost “hostname
$ds = Get-Datastore “datastore_name
$rp = get-resourcepool “pool_name

#Desired VM name

$vmname = “vm_name

New-VM -name $vmname -VMHost $vmhost -numcpu 2 -DiskMB 10240 -memoryMB 4096 -datastore $ds -guestID rhel5_64Guest -resourcepool $rp -cd -NetworkName dvPortGroup_Internal_VLAN110

To add an additional hard disk to the new VM:

Get-VM $vmname | New-HardDisk -CapacityKB (8*1gb/1024)

Alternative -guestID options:
windows7Server64Guest (2008 R2)
winNetEnterprise64Guest (2003 x64 Ent)

vSphere : PowerCLI Multipath Config

vSphere : PowerCLI Multipath Config

Round-robin configuration is per LUN, per host with vCenter 4.X and ESXi 4.x. When multiple hosts and datastores are in use this is a cumbersome and long-winded configuration that can easily be simplified with PowerCLI.

Single Host Configuration

Open PowerCLI and connect to a/the VCENTER server in your environment, change vcenter_name to match the hostname of your server:

connect-VIServer vcenter_name

To view hosts in a cluster, chage the cluster_name to match that in the vCenter GUI:

get-cluster cluster_name | get-vmhost

Confirm disks attached to each host:

get-cluster cluster_name | Get-VMHost | Get-ScsiLun -LunType disk

In the case of the environment I was working in I only wanted to change the configuration for EVA8400 disks attached to the VM hosts. There were also non-active/active storage devices attached which could not use round-robin.

To view the CanonicalName for all LUNs I used the command:

get-cluster cluster_name | Get-VMHost | Get-ScsiLun -LunType disk | fl -show canonicalname,vendor,capacitymb,model,luntype

From this you can analyse the CanonicalName and find the volumes that share the fist few digits, I ended up with all EVA8400 LUNs sharing ‘naa.6001438005’. An example output is below, you’ll note that two of the three LUNs share CanonicalName string (in red), the other does not (in green):

CanonicalName : naa.600508b1001c3a986c7a228dcad5099b
Vendor : HP
CapacityMB : 57207
LunType : disk
MultipathPolicy : MostRecentlyUsed

CanonicalName : naa.6001438005dee9f70000600003cf0000
Vendor : HP
CapacityMB : 153600
Model : HSV450
LunType : disk
MultipathPolicy : RoundRobin

CanonicalName : naa.6001438005deea3c0000900002a00000
Vendor : HP
CapacityMB : 102400
Model : HSV450
LunType : disk
MultipathPolicy : RoundRobin

Once you have identified which disks you want to change, confirm the string is working – adding a ‘*’ to the end of it, for example in order for me to view the EVA 8400 disks attached to a host:

$vmhost = get-VMhost hostname

Get-VMHost $vmhost | Get-ScsiLun -CanonicalName “naa.6001438005*”

CanonicalN ConsoleDeviceName LunType CapacityMB MultipathPolicy
———- —————– ——- ———- —————
naa.600… /vmfs/devices/disks/naa.600… disk 102400 RoundRobin
naa.600… /vmfs/devices/disks/naa.600… disk 153600 RoundRobin
naa.600… /vmfs/devices/disks/naa.600… disk 153600 RoundRobin
naa.600… /vmfs/devices/disks/naa.600… disk 230400 RoundRobin

I had four LUNs presented from the EVA8400, so I knew this was working, I had also configured these to be RoundRobin already. This enabled quick identification that these were the correct volumes. You can use the following script to map CanonicalName to DatastoreName as per the vCenter console as can be found here: http://communities.vmware.com/message/1435173#1435173

$h = Get-VMhost hostname

# collect VMFS datastore name and extent cannonical names into a hashtable
$dsLunList = @{}
$dsView = $h | Get-Datastore | ? {$_.Type -eq “VMFS”} | Get-View
foreach ($ds in $dsView) {
foreach ($diskExtent in $ds.Info.Vmfs.Extent) {
$dsLunList[$diskExtent.DiskName] = $ds.Info.Name

#populate datastore name for each lun if available
$lunList = @()
$h | Get-ScsiLun | % {
$lun = “” | select ConsoleDeviceName, CanonicalName, DatastoreName
$lun.ConsoleDeviceName = $_.ConsoleDeviceName
$lun.CanonicalName = $_.CanonicalName

if ($dsLunList.ContainsKey($_.CanonicalName)) {
$lun.DatastoreName = $dsLunList[$_.CanonicalName]

$lunList += $lun

$lunList | ft -show CanonicalName,DatastoreName

Confirm EVA LUN’s that are not configured for RoundRobin multipathing:

$vmhost = get-VMhost hostname

Get-VMHost $vmhost | Get-ScsiLun -CanonicalName “naa.6001438005*” | Where {$_.MultipathPolicy -ne “RoundRobin”}

To modify the LUN multipathing configuration you can use the following command:

$vmhost = get-VMhost hostname

Get-VMHost $vmhost | Get-ScsiLun -CanonicalName “naa.6001438005*” | Where {$_.MultipathPolicy -ne “RoundRobin”} | Set-ScsiLun -MultipathPolicy “roundrobin”

Multiple Host Configuration

To perform this for each node in a VM cluster use the following commands:

foreach ($vmhost in get-cluster cluster_name | get-vmhost) {
Get-VMHost $vmhost | Get-ScsiLun -CanonicalName “naa.6001438005*” | Where {$_.MultipathPolicy -ne “RoundRobin”} | Set-ScsiLun -MultipathPolicy “roundrobin”

Additional Information

naa.6001* is a HP storage device

naa.6006* is an EMC storage device

vSphere : vMA Setup

vSphere : vMA Setup

Import OVF template available form the VM Market Place: http://www.vmware.com/support/developer/vima/

Once completed on first boot a wizard will run, you and set an IP address and vi-admin user account password.

Press Alt-F2 from the VM console then login under vi-admin and execute these commands:

sudo vi /etc/sysconfig/keyboard

Change us to uk and reboot (if applicable!).

Login again via SSH or the console.

sudo vi /etc/ntp.conf

Hash out the serv 0/1/2 lines and enter the lines for your internal NTP servers (domain controllers will work):

Start the NTP service:

sudo service ntpd start

Configure NTP to start at boot:

sudo chkconfig ntpd on

Join the vMA appliance to the domain, modify the domain name, NETBIOSNAME and username:

sudo domainjoin-cli join domain.local NETBIOSNAME\\adminname

Enable connections to each ESXi host from the vMA:

vifp addserver vm01.domain.local
vifp addserver vm02.
vifp addserver vm03.domain.local
vifp addserver vm04.domain.local

Confirm server connections:

vifp listservers

Enable remote logging to the vMA applicance, modify theVM host names as required:

vilogger enable –server vm01.domain.local –numrotation 20 –maxfilesize 10 –collectionperiod 10
vilogger enable –server vm02.
domain.local –numrotation 20 –maxfilesize 10 –collectionperiod 10
vilogger enable –server vm03.
domain.local –numrotation 20 –maxfilesize 10 –collectionperiod 10
vilogger enable –server vm04.
domain.local –numrotation 20 –maxfilesize 10 –collectionperiod 10

Logs are now collected and stored under /var/log/vmware/

Confirm logging setup:

vilogger list

You’ll probably need to resize the /var/log partition (via gParted) or add an additional drive, and modifiy the log location configurationin /etc/vmware/vMA/vMA.conf

Exchange 2007 : Convert Linked Mailbox to User Mailbox

Exchange 2007 and 2010 : Convert Linked Mailbox to User Mailbox

During a migration cleanup I came across several user mailboxes that were ‘Linked’ and not ‘User’ mailboxes.

(In a non resource forest model) this is usually caused by;

  1. Associated External Account Permission
  2. Attribute ‘msExchMasterAccountSid’ is not null  / ‘msExchRecipientTypeDetails’ set to ‘2’ (both are usually as a result of 1)

Associated External Account Permission

Executing the following command did reveal that there was a permission for an External Account (despite the account being in the same domain as the mailbox):

{code lang:xml title:”Show Mailbox ExternalAccount Permission” lines:true hidden:false}$mbx = Get-Mailbox “alias”
$mbx | Get-MailboxPermission | ? {$_.accessrights -like “*ExternalAccount*”} {/code}

Attribute ‘msExchMasterAccountSid’ is not null  / ‘msExchRecipientTypeDetails’ set to ‘2’

Using adsiedit I confirmed that the ‘msExchRecipientTypeDetails’ attribute was set to 2 (Linked) and not 1 (User), and that the ‘msExchMasterAccountSid’ attribute was not null (not default!).

Correcting the Issue

Executing the following script in the Exchange Management Shell will change ALL mailboxes from Linked to user, modify the mailbox alias as required. Be sure this is what you want to do! In a Resource Forest scenario this would be undesirable to say the least!

{code lang:css title:”Cleanup Script” lines:true hidden:false}# Identify all LINKED mailboxes
$linkedmbx = Get-Mailbox | ? {$_.islinked -eq $true}

foreach ($mbx in $linkedmbx)

# Find and Remove Associated External Account Permission
$extacc = $mbx | Get-MailboxPermission | ? {$_.accessrights -like “*ExternalAccount*”}
Remove-MailboxPermission -Identity $mbx.DistinguishedName -User $extacc.User -AccessRights ExternalAccount

# Change the Mailbox Type and Null the msExchMasterAccountSid attribute for the user
$LDAPPath = “LDAP://” + $mbx.DistinguishedName
$LDAPPath | fl

$user = [ADSI]”$LDAPPath”
$user | fl


HP DataProtector : Cannot obtain Cell Manager host

HP DataProtector : Cannot obtain Cell Manager host

Came across this one today, the below error suddenly started to appear on a SQL backup that was working one day and stopped the next without any change or modification to the SQL server or Cell Manager:

Normal 0

[Critical] From: [email protected] “OSCDB”  Time: 2/10/2011 2:40:04 AM

      Cannot obtain Cell Manager host. Check the /etc/opt/omni/client/cell_server file and permissions of /etc/resolv.conf file.

On investigation I found that the CellServer registry key, listed below, was infact empty. Upon re-entering the CellServer (Cell Manager) name the backup started to work again:






SQL : SQL Server Management Studio Alternate Domain Credentials

SQL : SQL Server Management Studio Alternate Domain Credentials

Whilst working in a split domain, lets say Domain A and Domain B, environment we had a request for a user from Domain A to login using SQL Server Management Studio (SSMS) using Windows Credentials (Domain Account) to connect to a SQL instance using credentials from Domain B. The domains in this environment did not trust each other, they were isolated environments with only DNS stub-zones/secondary zones in place to ensure connetcivity to resources.

SSMS will not allow you to enter alternate Windows Credentials when connecting using Windows Authentication. It is however possible to achieve this using RunAs in the following way:

RUNAS /netonly /user:DOMAINB\user “C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe”

You can even set this as a shortcut which will then prompt for the supplied username’s password and then exeute SSMS.