Tuesday, June 25, 2013

Windows 8, Client Hyper-V & Networking

A while ago I upgraded my laptop to Windows 8, mostly because I wanted to trial using Client Hyper-V in comparison with Oracle VirtualBox which I had been using previously with some success, albeit with the occasional VM corruption - which is never a happy occurrence.

One of my biggest frustrations with Client Hyper-V has been its networking: VirtualBox networking more or less just works, but in comparison I've found Client Hyper-V networking much more hit-and-miss. In the simplest scenario, I wanted to be able to have a VM hosted in Client Hyper-V on my laptop, and to be able to have both my laptop, and the VM, able to see the Internet at the same time. Yea, I know, doesn't sound like much to ask.

With the help of http://geekswithblogs.net/bjackett/archive/2010/06/06/how-to-configure-remote-desktop-to-hyper-v-guest-virtual-machines.aspx I could run through the Virtual Switch Manager and create Internal and External Virtual Switches and have both my laptop and VM see the Internet and also be able to RDP to the VM, but each time I rebooted for some reason these settings were lost, and my laptop in particular could no longer see the Internet.

Thanks to the following post (and comments) I've been able to create a PowerShell script to rectify this each time my laptop is rebooted: http://blog.siliconvalve.com/2012/09/26/fix-windows-8-and-hyper-v-virtual-switch-problems/.

The PowerShell script simply disables & re-enables the "vEthernet (*)" network adapters for my Wi-fi and Ethernet created by Hyper-V Manager.

Disable-Netadapter -Name “vEthernet (WiFi)” -Confirm:$false
Enable-Netadapter -Name “vEthernet (WiFi)” -Confirm:$false

Disable-Netadapter -Name “vEthernet (Ethernet)” -Confirm:$false
Enable-Netadapter -Name “vEthernet (Ethernet)” -Confirm:$false


I then schedule this script to be executed each time my laptop starts via Windows Task Scheduler.

On the "General" tab illustrated below, the key parts are to ensure you select an account with appropriate permisssions (eg a member of the local Administators group), select the option to run whether a user is logged on or not, and to run with highest privileges.

 
On the "Triggers" tab illustrated below, add a trigger for the task to run at system startup.

 
On the "Actions" tab illustrated below, add a new action to execute the PowerShell script.

 
The action needs to call the PowerShell executable, and pass in the name of the file containing the PowerShell script to be executed.


The key bits here are to set the program/script field to the path to the PowerShell executable, something like "%windir%\System32\WindowsPowerShell\v1.0\powershell.exe", and to set the value of the arguments field to the path to the file containing the PowerShell script. Most importantly (at least in my experience) you need to wack an ampersand (&) character at the start of the value for the arguments field, and enclose the path to the file in single quote (') characters, for example "&'C:\Reset Network Bridge Adapter.ps1'" (excluding double quote characters).

Hope this helps someone.

Saturday, June 1, 2013

SSIS: Time zone conversion

I needed to convert date/time data within a SSIS data flow from US Central Standard Daylight Time (UTC-5:00) to my local timezone which could vary between AU Central Standard Time and AU Central Standard Daylight Time (UTC+9:30 or UTC+10:30). The source data was guaranteed to always be UTC-5:00, so I only needed to allow for the potential variance for AU daylight savings.

I used a SSIS script transform to achieve the desired result:



And the key code being contained in the ProcessInputRow method of the script transform:

public override void Input_ProcessInputRow(InputBuffer Row)
{
  Row.PurchaseDateLocalTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(

    new DateTimeOffset(
      Row.PurchaseDate,
      new TimeSpan(-5, 0, 0)),
    "Cen. Australia Standard Time")
  .DateTime;
}