Monday, September 22, 2014

Live Migrating multiple VMs [HyperV 2008]

This powershell script will let you live migrate multiple virtual machines serially.
The script will ask you to select which machines do you want to migrate and to which destination node as in the below screenshots

To run the script on Windows 2008 R2, you need to install powershell 3.0


Import-Module FailoverClusters

$clustername = Get-Cluster

$vms = Get-ClusterGroup  -Cluster $clustername  | Out-GridView -PassThru -Title "Select VMs to live migrate"
$destination = Get-ClusterNode | Out-GridView -Title "Select destination HyperV host" -PassThru
$count = 0

foreach ($vm in $vms){
 $count += 1
 $total = $vms.count
 write-output "[$count/$total] migrating $vm to $destination..."
 Move-ClusterVirtualMachineRole -Name $vm -Node $destination

write-output "All Done"

Wednesday, June 25, 2014

Windows out of the box cmd send mail one liner with variables in subject/body

powershell -Command "Send-MailMessage -To -Cc -From -SmtpServer -Subject $('Mail from computer: ' + (hostname)) -Body $((date).ToString() + ' Mail from computer: ' + (hostname))

Tuesday, June 24, 2014

[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot find the user 'AdtServer', because it does not exist or you do not have permission

I was installing SCOM ACS 2012 R2 and configuring it to use SQL authentication. This is not to collect events from an untrusted domain, I was just implementing redundant ACS collectors as described here which would require the collectors to use SQL authentication to connect to the backend database.

ACS setup completed successfully on all ACS collector servers, but the Audit Collection Services shuts down shortly after starting and logs this event

Error occured on database connection:

Status: 0x04080000

ODBC Error: 15151

ODBC State: 42000

Message: [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot find the user 'AdtServer', because it does not exist or you do not have permission.

Database: SqlWriter

Connection: Maintenance



The reason this happened was because I precreated the SQL account and gave it dbcreator role then supplied it to the ACS setup. I then discovered that the ACS installer would actually create the account itself, surprisingly it did not complain that the account already existed and completed successfully but apparently something was still broken.

I uninstalled ACS, deleted the SQL account then reinstalled ACS and now it works.