How to re-create symlinks of VM configs in Hyper-V using PowerShell

  • Hyper-V keeps VM config at %ProgramData%\Microsoft\Windows\Hyper-V\Virtual Machines\ as a symbolic link (aka symlink) to the original location.

You may get them broken due to various reasons, e.g.:

  • Server disaster and then recovery
  • Upgrade to the next version of OS/Hyper-V and then rollback
  • Migration of virtual machine

To restore functioning you need to create a symlink for each xml config, i.e.:

mklink %ProgramData%\Microsoft\Windows\Hyper-V\Virtual Machines\{guid}.xml d:\MyVM\Virtual Machines\{guid}.xml

But how to automate this if you have tens of VMs? Here’s the command:

Get-ChildItem -Recurse *.xml | `
New-Symlink -LiteralPath { Join-Path -Path '%ProgramData%\Microsoft\Windows\Hyper-V\Virtual Machines' -ChildPath $_.Name } -TargetPath { $_.FullName }
Posted in Infrastructure | Tagged , | Leave a comment

How to select Azure subscription if you have more than one using PowerShell

If you have more than one Azure subscription in your account and try to upload a vhd using the instruction:

  1. Get-AzurePublishSettingsFile
  2. Import-AzurePublishSettingsFile d:credentials.publishsettings
  3. Add-AzureVhd -LocalFilePath d:my.vhd -Destination http://example.com/blob/container

You may get an error saying that selected account doesn’t have given blob.
That’s because the first subscription is selected by default and the target blob is in the another one.

To select the proper subscription use the following command:

Get-AzureSubscription | Select -Last 1 | Select-AzureSubscription

(For instance, the last one).

Posted in Infrastructure | Tagged , | Leave a comment

Could not load file or assembly ‘Microsoft.AnalysisServices, Version=11.0.0.0

If you’re getting the following error upgrading TFS 2012 RTM to ver. 2012.3:

TF255356: The following error occurred when configuring the Team Foundation databases:
TF400711: Error occurred while executing servicing step Upgrade Warehouse for component UpdateWarehouseVersion during FinishInstallUpdates: Could not load file or assembly ‘Microsoft.AnalysisServices, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91‘ or one of its dependencies. The system cannot find the file specified.. For more information, see the configuration log.

then just install Microsoft SQL Server 2012 Analysis Management Objects from Microsoft SQL Server 2012 Feature Pack (expand the Install Instructions node).

Note that you’ll might need to restart the setup wizard or even server itself before the error will go away.

Posted in Infrastructure | Tagged , , | Leave a comment

How to issue a self-signed certificate

To have a properly working SSL web site you have to assign a SSL certificate to it. A real one costs real money. Easily especially for development to issue a self-signed one.

To create certificates I will use MakeCert.exe that is shipped with Windows SDK (usual path is %ProgramFiles%Microsoft SDKsWindowsv7.1ABin).

First step: create a certificate at TempCA.cer with subject name CA=TempCA with private key kept in TempCA.pvk:

makecert -n "CN=TempCA" -r -sv TempCA.pvk TempCA.cer

Second step: create a certificate at SignedByCA.cer in container SignedByCA with subject name CN=example.com (probably should correspond to the web site address) signed by root authority certificate TempCA.cer with private key at TempCA.pvk and save it into the store named My for CurrentUser:

makecert -sk SignedByCA -n "CN=example.com" -iv TempCA.pvk -ic TempCA.cer SignedByCA.cer -sr CurrentUser -ss My

Third step: generate Personal Information Exchange (.pfx) file at TempCA.pfx from certificate TempCA.cert and private key TempCA.pvk (with no password):

Pvk2Pfx -pvk TempCA.pvk -spc TempCA.cer -pfx TempCA.pfx -f

See MSDN for more details.

Posted in Infrastructure | Tagged | Leave a comment

TDD kata by implementing LINQ

I just discovered that what I’m writing right now is a new TDD kata. Very interesting and useful TDD kata.
Interesting because usual C# developer uses LINQ extension methods on every day basis and it is interesting to re-implement by your own what you use so often.
Useful by the same reason, and also if you have a project stuck with .NET 2.0 then you’re getting a nice, written by yourself, fully tested LINQ extension methods replacement.
Sounds cool! Doesn’t it?

So here’s the kata description:

  • Start up with simple methods such as Count(), Where() and Select()
  • End up with complex methods such as GroupBy() and Aggregate()
Posted in Programming | Tagged , | Leave a comment

The Cult of Legacy

In our company’s software development division due to many reasons, most of them are unknown to me, we apparently have The Cult of Legacy:

  • You can discuss anything but Legacy
  • You can criticize anything but Legacy
  • You can refactor anything but Legacy
  • You can rework anything but Legacy
  • You can fix anything but Legacy

Something is rotten in this state of Denmark…

Posted in Programming | Tagged | Leave a comment

Your constructor smells

A code like the following looks as a “code smell” definitely:

public ProductProvider(
    IProductDataProvider dataProvider = null,
    IProductDecorator decorator = null,
    IProductSearchCriteriaParser parser = null,
    IProductInventoryDataProvider inventoryProvider = null,
    IProductSessionDataProvider sessionProvider = null,
    IContentProvider contentProvider = null,
    IProductQueueProvider queueProvider = null)
{
}

But unfortunately nothing I can do. What can I say? Alas!

Posted in Programming | Tagged | 1 Comment

Serfs you were and serfs you are

A wonderful phrase once said by Richard II to peasants in the of Peasants’ Revolt of 1381:

Serfs you were and serfs you are; you shall remain in bondage, not such as you have hitherto been subject to, but incomparably viler. For so long as we live and rule by God’s grace over this kingdom we shall use our sense, our strength and our property so to teach you, that your slavery may be an example to posterity, and that those who live now and hereafter, who may be like you, may always have before their eyes and as it were in a glass, your misery and reasons for cursing you, and the fear of doing things like those which you have done.

What in England in XIV century that in Russia all the times up to XXI.

Posted in Thoughts | Leave a comment

Isolateware

After discussion with my colleague and considering the policies and practices adapted and used in our company towards globalization and isolation of software to write and support, I want to try to formulate a software development methodology anti-pattern:

A software called on to be global, used worldwide, but developed by separate, isolated groups is broken by design. So called Isolated Software, or briefly – Isolateware.

Plague on both your houses managers and architects responsible to the decisions led to such results.

Posted in Programming | Tagged | Leave a comment

“Black Hole” software anti-pattern

During digging into eCommerce5 codebase and discussing ongoing impressions with my colleague,  I just discovered a software design anti-pattern I called “Black Hole”.

As a workaround I declare a rule:

Any variables passed into constructor then should be available through a read-only property.

Honestly I haven’t invented the explanation yet.

Posted in Programming | Tagged | 2 Comments