Wednesday, August 7, 2013

Migrating TFS (2010 or 2012) Personal Queries from one project to another via Powershell

The powershell script below can be saved run on a users system to migrate their personal TFS Queries from one project to another.  This is useful when migrating from TFS 2010 to TFS 2012.

You will need to update the script Source and Target Server URLs, TPC and Projects.  I went down the path to hard code them and not take them as arguments so users did not have to enter anything.  The script will throw errors if the query being migrated is not valid on the target project.
function ProcessQueryItem ($queryFolder, $parentFolder, $sourceProjectName)
{
 $newItem = $null
 foreach ($subQuery in $queryFolder)
 {
  if ($subQuery -is [Microsoft.TeamFoundation.WorkItemTracking.Client.QueryFolder])
  { 
   $newItem = new-object Microsoft.TeamFoundation.WorkItemTracking.Client.QueryFolder -ArgumentList    @($subQuery.Name)
   if (-not $parentFolder.Contains($subQuery.Name))
   {
    Write-Host "Adding Query Folder $subQuery"
    $parentFolder.Add($newItem);
    $WIStoreRight.Projects[$RightProject].QueryHierarchy.Save()
    ProcessQueryItem $subQuery $newItem $sourceProjectName
   }
   else
   {
    Write-Host "Query Folder "$subQuery.name" already exists" -foregroundcolor Yellow
   }

  }
  else
  {
   Write-Host "Creating query "$subQuery.Name
   $oldDef = [Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition]$subQuery
   $queryText = $oldDef.QueryText.Replace("$sourceProjectName\", "$RightProject\")
   $queryText = $queryText.Replace("[System.IterationPath] under '" + $sourceProjectName + "'", "[System.IterationPath] under '" + $RightProject +"'");
   $newItem = new-object Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition -ArgumentList @($subQuery.Name,$queryText)
      
    if ($parentFolder.Contains($subQuery.Name) -ne $true )
    {
    $parentFolder.Add($newItem)
    $WIStoreRight.Projects[$RightProject].QueryHierarchy.Save()
    }
    else
    {
    Write-Host "Query Definition $subQuery already exists" -foregroundcolor Yellow
    }
  
  }
 }
}

[URI]$Projecturileft = "http://sourceServer:8080/tfs/SourceTPC/"
$leftProject = "SourceProject"
[URI]$ProjecturiRight = "http://targetServer:8080/tfs/TargetTPC/"
$RightProject = "TargetProject"

[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.WorkItemTracking.Client')
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.Client')
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.Server')

$tfsleft = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($Projecturileft) 
$WIStoreleft = $tfsleft.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore]) 
$WIStoreleft.RefreshCache($true)
$WIStoreleft.SyncToCache() | out-null

$LeftQuerystore = $WIStoreleft.Projects[$LeftProject].QueryHierarchy

$tfsRight = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($ProjecturiRight) 
$WIStoreRight = $tfsRight.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore]) 
$WIStoreRight.RefreshCache($true)
$WIStoreRight.SyncToCache() | out-null
foreach ($queryFolder in $LeftQuerystore)
{
 if ($queryFolder.IsPersonal)
 {
  $RightMyQueriesFolder = [Microsoft.TeamFoundation.WorkItemTracking.Client.QueryFolder]$WIStoreRight.Projects[$RightProject].QueryHierarchy["My Queries"];
  
  ProcessQueryItem $queryFolder $RightMyQueriesFolder $leftProject
  Write-Host "Personal Queries Migrated"
 }
}

Monday, July 15, 2013

How to use WIQL to query for work items in TFS 2012 via the URL

These days I spend a large amount of time in TFS 2012. 

In TFS 2008 and 2010 users could use the q.aspx page to run a query using WIQL as defined by the 2010 WIQL spec (http://msdn.microsoft.com/en-us/library/bb130306(v=vs.100).aspx). Ken O' Bonn has a great post on this at http://blogs.msdn.com/b/kenobonn/archive/2009/05/28/how-to-link-directly-to-tswa-2008-or-2010-beta1-work-items-or-queries.aspx

However in TFS 2012 the URLs for everything changed and I was unable to find any information on how to accomplish the same task. How can you provide a URL to users that queries for work items without writing and saving a query to the TFS server. 

The key is I don't want to save a query to TFS.   

So after some trial and error I found the way!

http://<ServerAddress>:8080/tfs/<TPC Name>/<Project>/_workitems#_a=query&wiql=<WIQL>

An example:

http://tfstest:8080/TPC1/project1/_workItems#_a=query&wiql=select id, [System.areapath] from workitems

The WIQL for 2012 is defined at http://msdn.microsoft.com/en-us/library/bb130306.aspx#language






Tuesday, May 28, 2013

Why solar (PV) in Seattle Washington ROCKS!

I just had my 4.3kW solar array installed on my home in Seattle.  The upfront cost is a little high but I should still be able to pay off the system in less than 8 years.  This is possible thanks to Washington States amazing Solar credits.

Seattle City Light (and other Washington residence) pay amazingly low energy rates for residential our power. Even with this low rate people installing solar panels can relatively quickly get a good ROI on their panels.

  • Seattle has the lowest rate compared to the top 25 largest cities in the US.
  • The 2013 rate for SCL customers is $.0466/kWh for the first 10kWh. 
  • The national average rate is $0.129/kWh  and people in New York pay ~$0.209/kWh

How can I pay back my panels so fast?

The Washington State Solar generation incentive program.  While not the exact name it is a Performance-Based Incentive that gives the array owner a dollar amount for every kW they generate no matter if they use that power in their home or send it back to the power grid.  The current incentive is in place until June 30th  2020. 

In short this incentive give me $.54/kWh I generate on-top of my reduced power bill and any Net metering (where I sell power back to my power company).  I get the full 54 cents because my Itek Solar Panels and BlueFrog inverters are MADE IN WASHINGTON.  If you have non-Washington made components the incentive drops significantly

Many other states don't provide such an incentive nor do they give you full price on the net metering.  But Washington does!  Yet another reason why living in Seattle ROCKS. 

Other State Example:
My partner's parents have a ~7kW system at their home on Oahu Hawaii.  This system generate power for ~10 hours a day and significantly lowers their power bill.  Hawaii Power Company (HECO) current rate is ~$.32/kWh.  This is 7 times higher than the rates I pay in Seattle.  At that rate they are still expected to pay off their system in ~5 years.  This very high rate (and rebates) is the only way the $40k+ system can pay for its self in a timely fashion.




Friday, April 26, 2013

Getting 4.3kW of Solar Panels in Seattle!

I know people say it rains a lot in Seattle. Truth is that it "mists" a lot and is just gray more often than not. 

But either way the SUN is there to give everyone free energy if they want it. 

My new home finally has enough roof space for Solar Panels (PV) that will let me make the investment worth while. 

Puget Sound Solar had the best price and was able to get an install date that was before the June 30th 2013 Washington sales tax exception cut off.  Will Sumner from Puget Sound Solar came out and went up onto my roof to do his survey.  He answered all my questions and was able to point me to Puget Sound Cooperative Credit Union for my zero down low rate loan for the full project. 

My install date is currently May 14th 2013. 

I am going with the Itek 240W modules and the BlueFrog APSYC500-MIW micro inverters.  This will get me the .54 /kWh all Washington incentive and provide 4.3kW of capacity.  All parts are made in Washington!!

I expect full payback in less than 8 years!  WOOT WOOT. 

Puget Sound Solar has sent me a few forms I needed to complete and then mail a check to Seattle City Light for my production meter.  Everyone has been great and after meeting with the Project Manager Jacob Hanson today everything seems to be on track!

My Bee Hive Warning sign

I got the sign below from http://www.bbhoneyfarms.com/store/

They were cheap and have done a great job to warn people that I have a hive.

They also let people know Bees are not out to hurt anyone.  Just don't mess with their home.




Caution
No Trespassing
Honeybees

TFS 2012 how to get Last Known good build via Powershell

The following script will return the last successful build on a given build definition. 

Save the following to a .ps1 file

$project = "testproject"
[URI]$Projecturi = "http://tfsserver:8080/tfs/DefaultCollection/"
function Wait-GetLKGBuild {
 [CmdletBinding()]
 PARAM (
  [Parameter(Mandatory=$true)]
        [string]$buildDefinitionName
    )

    [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.Build.Client')
    [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.Client')

 $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($Projecturi)
    $buildserver = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
         
    $rbBuildDefinition = $buildserver.GetBuildDefinition($project, $buildDefinitionName)
 $build = $buildserver.GetBuild([Uri]($rbBuildDefinition.LastGoodBuildUri));
  New-Object PSObject -Property @{
                Buildnumber = $build.BuildNumber; 
    Requestedfor = $build.RequestedFor;
                Status = $build.Status;           
                CompilationStatus = $build.CompilationStatus;           
                Start = $build.StartTime;           
                End = $build.FinishTime;           
                DropLocation = $build.DropLocation;           
                SourceGetVersion = $build.SourceGetVersion;           
                }           
         }
}
Wait-GetLKGBuild $buildDefinitionName

My first Bee hive 2013

2013 is now the first year that I live in a house with enough room to have a bee hive.  On April 20th 2013 I picked up by bee package from the Ballard Bee Company. 

My queen and her ~10,000 followers seem to be doing well.

At day 2 I opened the hive to make sure the queen made it out of her cage by eating through the mini-marshmallow.  She made it out. 

I will open the hive again on day 7 to see if she has started laying eggs.

Here are some pictures. 



Sunday, February 5, 2012

Home Circuit Power Monitoring - Part 2

It has been about 6 months from when I installed per circuit power monitoring in my home (http://www.mikepoulson.com/2011/07/new-home-power-monitor.html).

In January 2012 I started injecting all my power data into a SQL DB (SQL Express).  This has allowed me to use Tableau (www.tableausoftware.com) to analyze the utilization.

Here is an example of that power consumption in my House. 


You can see my office plugs (where my Media Center is located) is my #1 consumer of power.  You can see that the TV and Kitchen outlets are in second place.

I used the data shown here to determine that my 1st floor lights use a lot of power.   This weekend I replaced those 400 Watts of lights with new LEDs (Phillips Ambient LED, http://www.amazon.com/Philips-409904-Dimmable-AmbientLED-12-5-Watt/dp/B004IUMGV4).

You can see from the graph below how much power I used to watch the "BIG GAME".

Based off this and a power cost of $.09/Kwh it cost ~$.24 to watch the game.
(539 watts /1000 = .539Kw * 5 hours = 2.70KwH * .09 = $.245)

This does not include the cost of beer, snacks, the cookies, steaks or stress. 

To get this to work I use tenEcmServer and tenEcmDB from http://tenholder.net/tenWare2/tenEcmServer/default.aspx.  The tenEcmDB needed a little modification to work with SQL Server.  By default it works with SQLLight.  With the tenEcm components I can monitor my BrulTech equipment and provided extensive reporting on it.

Wednesday, October 5, 2011

Not a big fan of new Microsoft Touch mouse

I upgraded from the Microsoft Touch Arch mouse to the new TouchMouse.  I must say I am not a fan.

The new mouse looks nice and all but does not work as well as I would like.


The new TouchMouse has a single button.  It utilizes touch sensors to detect if you are using the left or right finger to press down.  The problem that I have it is I rest my fingers on my mouse.  This causes the mouse to think I am using the multi-touch (two finger) to minimize or maximize windows. It also sometimes thinks I am pressing the right button when I press the left.

Tuesday, August 16, 2011

Home Automation with Insteon - New Ceiling fan

I got my first Insteon switches and setup in 2005. At the time it was an early product and still had issues and did not have the number of options that exist today.

I live in a 4 story townhome that faces southwest. Because of this the top floor can get super warm in the summer time. To help resolve this we desided to install a ceiling fan where there was just a light before.

There are 2x 3 way switches that control the light at the top of my stairs. There are also lights on the wall controlled by the same switches.


Here is how it looked before I started.



Insteon

I replaced the 2 standard decora switches with Insteon KeypadLinc Switches .  Then added 2 wire-in controllers.  1 dimming controller and 1 non-Dimming controller.

Once all that was done I installed the new fan and wired the fan load to the non-dimming controller and the lights to the dimming controller.

Here is what it looks like now.

Friday, August 5, 2011

WDS and Symbolic Links

Windows Deployment Services (WDS) is all my team and I use for OS deployments. We regularly use the $OEM$\$1 option to copy files and scripts to the target install. More on $OEM$

Recently we started updating scripts that are in a $OEM$, $$ or $1 folder. This was very time consuming because you had to update a large number (~50) different images.

The solution to this problem: Hard Links http://msdn.microsoft.com/en-us/library/aa365006(v=vs.85).aspx
We use the Mklink command to create a Hard link to a “source file”. WDS follows this link and copies the script\file to the target OS during install. This allows us to have a GOLD set of scripts that will get copied yet we only have to make a change in 1 location.

The important thing when making the link with mklink is to pass the /k argument. This will tell mklink to make a hard link not a Symbolic link. You can find more on Mklink at http://technet.microsoft.com/en-us/library/cc753194(WS.10).aspx


WDS will not work with a Symbolic link and will throw an error like:
Windows cannot copy files from \$OEM$ to C:\$WINDOWS.~LS\Sources. The files do not exist. Make sure all files required for installation are available, and restart the installation. Error code: 0x80070003]


This works on Windows Server 2008, Windows Server 2008 R2.

10 Years from last post

 Well world!   After the last almost 10 years I have been up to a few things in life and work.  Most recently I was working at Microsoft on ...