Tuesday, December 6, 2011

Enable all email users on Lync with a one liner

Here's a quick hit:  You have your users in Active Directory, you have Exchange, you just installed Lync.  How can you quickly give everyone with an email address a matching Lync account?

In the Lync Server Management Shell (which is just Powershell with the Lync modules loaded) all one line:

Get-CsAdUser | Enable-CsUser -SipAddressType EmailAddress -RegistrarPool "FQDN_of_your_Lync_server_or_pool"

That's it!  Every user with an email address in AD will have a lync account, but it will skip (error out really) all the service accounts or other accounts that don't have email.

Monitoring Microsoft Cluster Shared Volumes

So you built a nice failover cluster (in my case for Hyper-V) using Cluster Shared Volumes on Windows Server 2008.  Great! 

How do you know when the are full?  The base product doesn't give you a quick and easy way of monitoring disk usage of a CSV, just of the base disk letter.  The lastest version of Operations Manager DOES appear to have counters to monitor and alert on CSVs, but if you don't have that running you might want to consider this shoestring approach:

Every morning I (and the other admins) recieve an email similar to this:



First, the brains of this operation were taken from this MSDN blog post: 
http://blogs.msdn.com/b/clustering/archive/2010/06/19/10027366.aspx
I did some modification to the script to get the bare minimum results I need to format properly in an email.

Second, I am a batch file guy from way back, using powershell now but by no means a guru and never got around to learning VBScript.  I'm sure one of you reading this will say "But you can send SMTP mail directly from Powershell" and you would be correct, but I haven't tried that yet.  If anybody does make that happen or groks the text output in a more meaningful way I would love to hear it, leave a reply!  One idea - if the last column could be grep'd for values you only send the email if a value is less than x%.

The idea is we are going to run that powershell script in task scheduler (I have it set for once a day, suits my needs) and have a command line mailer send me the results. 

You will need:
  1. Admin access to one of the servers hosting the CSVs
  2. A command line SMTP sender, I like BMAIL - been around for years, works and is free and reliable
    http://www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm

The process:
  • Create a folder on C:\ called "jobs".  If you use a differnet name you will have to modify my stuff.
  • Save the text below as "DisplayCSVInfo2.ps1" in that folder
Import-Module FailoverClusters
$objs = @()
$csvs = Get-ClusterSharedVolume
foreach ( $csv in $csvs )
{
   $csvinfos = $csv | select -Property Name -ExpandProperty SharedVolumeInfo
   foreach ( $csvinfo in $csvinfos )
   {
      $obj = New-Object PSObject -Property @{
         Name        = $csv.Name
         Path        = $csvinfo.FriendlyVolumeName
         Size        = $csvinfo.Partition.Size
         FreeSpace   = $csvinfo.Partition.FreeSpace
         PercentFree = $csvinfo.Partition.PercentFree
      }
      $objs += $obj
   }
}

$objs | ft -auto Name,Path,@{ Label = "Size(GB)" ; Expression = { "{0:N2}" -f ($_.Size/1024/1024/1024) } },@{ Label = "FreeSpace(GB)" ; Expression = { "{0:N2}" -f ($_.FreeSpace/1024/1024/1024) } },@{ Label = "PercentFree" ; Expression = { "{0:N2}" -f ($_.PercentFree) } } | Out-File c:\jobs\result.txt



  • Save the Bmail executable (bmail.exe) in the same folder.
  • save the following to a text file named  "csvcheck.cmd"
del c:\jobs\result.txt
powershell.exe C:\jobs\DisplayCSVInfo2.ps1
c:\jobs\bmail -s smtpserver.yourdomain.com -h -t
your-email@yourdomain.com -f Clustername@yourdomain.com
-a Clustername_CVS_STATUS -m c:\jobs\result.txt -c

To break that last command down, it is saying:
  1. delete the old results file
  2. call powershell to run the data generating script
  3. run Bmail.exe with these switchs/arguments:
    • -s your_mail_server_name  (you have to have an email system that accepts smtp messages from your server.  I'm using Exchange 2010)
    • -h  (create standard headers)
    • -t  your_email_addy  ("To:"  I set up a group with all the sys admin's email in it)
    • -f  some_real_or_fake_email_addy ("From:"   doesn't have to be a real email address, just have the usual format to get through basic spam filtering routines)
    • -a some_tetxt  ("Subject:"  make it anything yo like, I use the name of the cluster being monitored)
    • -m c:\jobs\result.txt  (use the indicated text file as the body of the message)
    • -c  (put a CR/LF in between the body and header so Outlook will display it properly)
  4. Schedule the job in task scheduler.  Make sure the account you use can write and delete to the c:\jobs directory you created.  (Local System is probably fine)

Monday, December 5, 2011

Linux on Hyper-V, migrate RedHat VM from XEN to Hyper-V

Short version - we are a mostly Microsoft shop and after a brief foray into XEN on RedHat I now have to migrate a bunch of RedHat ENT 5.x virtual machines from Xen to Hyper-V.


If you just need to migrate a hardware based linus install to a Hyper-V VM, just follow the instructions in the first reference at the bottom of this page.


Surprisingly, couldn't find much out there on this one, but was able to cobble this procedure together from several different posts.  Everything below was done on RedHat Ent 5.x virtual machines running GRUB and Hyper-V on Windows Server 2008 R2 SP1.  For other/newer linux with GRUB2 or other bootloaders you will have make some adjustments.


 It turns out that the linux .img format created by the DD command (which is also the Xen VM format) can be converted to the .vhd format as long as the .img is smaller than 127 GB.  (VHDtool can't handle a larger file)


1. The kernel your XEN VM is running won't work outside the XEN enviroment, you need the plain vanilla hardware version.  Luckily it isn't too hard, I used Yum here, if you have/like another way than have at it.

yum install kernel
2. The new kernel need to create it's boot drivers, with this command:

mkinitrd -v -f --builtin=xenblk  /boot/nameoftheinitrd   kernel-version
An example from kernel version 2.6.18-274.12.1.el5:

mkinitrd -v -f --builtin=xenblk  /boot/initrd-2.6.18-274.12.1.el5.img   2.6.18-274.12.1.el5

3. Now make sure the /etc/sysconfig/kernel file refers to the new kernel. Do so by including the line DEFAULTKERNEL=kernel in this file.


4. edit /boot/grub/device.map. The idea is that the XEN disk type is xvd, but the common IDE type is hd.  The first & second XEN hard drives would be xvda and xvdb, but under hardware or HyperV they should be hda and hdb.
change this line:
(hd0) /dev/xvda
to:
(hd0) /dev/hda


5. Edit /boot/grub/menu.1st so that "default=0"

6. Shutdown VM   (xm destroy)

7. Use WinSCP (free, on internet) to copy the xem vmname.img file to a location on a stand alone hypervisor (temporary location to first run the VM).

8. Use VHDtool.exe (free, internet) to convert the linux img file to a VHD format (This is very fast, less than a second)
VHDTool /convert c:\VMNAME.img

9. rename the file from __.img to ___.VHD

10. create the VM in the HyoerV manager, using your VHD file as the hard drive.  it should boot right up

11. If you get a mesage after booting that 
"INIT: id "co" respawning too fast: disabled for 5 minutes"
then comment out (#) the line in /etc/inttab under 'gettys' that begins with "co"  (it is the xen terminal type)







References:
1.  http://blogs.technet.com/b/enterprise_admin/archive/2010/05/13/linux-p2v-with-dd-and-vhdtool-easy-and-cheap.aspx
Summary, should it ever be deleted:

1. On Linux machine - you will need free space on a local disk or mapped drive equal to the partition size.  Use DD to make a binary image copy (_.img file) of the linux install.  This can take several hours (all depends on the size of the data) format:

dd if=/dev/hda of=/mnt/rhel54.img


"dd" is the command, "if=/dev/hda" is the input - may not be the hda disk type, use "fdisk -l" to see what your hard drive is.  Another common name is "/dev/cciss/c0d0"
If you can map to a windows drive to write to, this is the format to mount the remote share:

mount –t cifs –o username=administrator //192.168.0.10/D$ /mnt


If you use another partition on linux to store the image, you can use WinSCP (free - internet) to transfer the image to the windows server after creating the _.img file.


2. Use VHDtool.exe (free, internet) to convert the linux img file to a VHD format (This is very fast, less than a second)

VHDTool /convert c:\VMNAME.img


9. rename the file from __.img to ___.VHD


10. create the VM in the HyperV manager, using your VHD file as the hard drive.  


11. You will need to install the version of "Linux Integration Services" that matches the version of RedHat you are working with (a download from microsoft).  As of this writing RedHat 5.0 to 5.5 uses Integration Services 2.1.  It appears that 5.6 and higher can run without the integration Services (it is optional for advanced features)


The install instructions are included with the product, it involves pressenting the .iso file to the VM through HyperV manager, then install at the linux console.  


This product recomplies the kernel, so you have to disabled Kernel updates in Yum.conf.  If the kernel is updated the VM will no longer be bootable as the Microsoft linux drivers won’t exist in the new kernel.  Possible long term solution here:
http://support.microsoft.com/kb/2387594




2. http://searchservervirtualization.techtarget.com/tip/Xen-to-KVM-virtual-machine-migration-A-step-by-step-guide