Peace For All

September 9, 2011

How To Properly Get The Drive Letter of a Mounted VHD in PowerShell

Filed under: PowerShell — Tags: , , , , , — Devlin Bentley @ 1:06 pm

There are multiple ways to get the drive letter of a mounted VHD in PowerShell. The most common way is to enumerate all drive letters, mount a VHD, enumerate all drive letters again, and find out which new drive letters have appeared. This strategy is NOT safe and will break down if you have more than one program or instance of your script trying to use this method at the same time.

The reason why it isn’t safe is quite obvious. Assume you have a machine with just one active drive at start, “C”.

  1. Script 1 enumerates all drives, gets back a list {“C”}
  2. Script 1 mounts VHD1, VHD1 is assigned drive letter “D”.
  3. Script 2 enumerates all drives, gets back a list {“C”, “D”}
  4. Script 2 mounts VHD2, VHD2 is assigned drive letter “E”.
  5. Script 1 enumerates all drives, gets back a list {“C”, “D”, “E”}

At this point Script 1 is not sure which drive belongs to the VHD it mounted. If you have a UNIQUE volume name, great! You can do select based on volume name and you are in luck.

If you don’t though, you have ran into the limitations of this technique.

But there is a better way!

Credit goes out to the PowerShell Management Library for HyperV. They do it properly!

First thing to know is that VHDs are mounted as virtual SCSI Disks. A virtual SCSI Disk can be uniquely identified by a combination of LUN, SCSI Target ID and SCSI Port. Our basic strategy is going to be mapping from Mounted VHD path to a Virtual SCSI Disk and then digging into that Disk object to find out what drive letter it has.

So lets break out some WMI shall we?


# Given the full path to an already mounted VHD and the name of a volume on it,
# returns the drive letter that VHD was mounted to
function GetDriveLetterOfMountedVHD($FullPathToVHD, $VolumeName)
{
   $MountedDiskImage = Get-WmiObject -Namespace root\virtualization -query "SELECT * FROM MSVM_MountedStorageImage WHERE Name ='$($VHDPath.Replace("\", "\\"))'"
   $Disk = Get-WmiObject -Query ("SELECT * FROM Win32_DiskDrive " +
        "WHERE Model='Msft Virtual Disk SCSI Disk Device' AND ScsiTargetID=$($MountedDiskImage.TargetId) " +
        "AND   ScsiLogicalUnit=$($MountedDiskImage.Lun)   AND ScsiPort=$($MountedDiskImage.PortNumber)" )
    $Partitions = $Disk.getRelated("Win32_DiskPartition")
    $LogicalDisks = $Partitions | foreach-object{$_.getRelated("win32_logicalDisk")}
    $DriveLetter = ($LogicalDisks | where {$_.VolumeName -eq $VolumeName}).DeviceID
    return $DriveLetter
}

The key thing to notice here is that you are asking WMI for a MountedStorageImage based on the full path of the VHD you mounted. This guarantees that you are not conflicting with any other script’s VHD activities. All the info returned to you is only about the VHD you mounted.

The rest of the function is pretty straight forward. It can actually all be done in one line but I expanded it out here for clarity.

  1. Using the knowledge you have about the MountedDiskImage’s assigned Virtual SCSI info, get a Win32 Disk Drive by searching on the matching LUN, TargetID and SCSI Port
  2. Get a list of partitions on that disk.
  3. Get a list of logical disks (the things you see in My Computer) associated with each partition
  4. Return the drive letter of the volume that you want.

Now if your logical disks happen to have identical volume labels you can index into $LogicalDisks and pick out which one you want that way, and so long as you don’t go rearranging partititions in your VHD that may work just fine. In addition, you can replace the last where {$_.VolumeName -eq …} bit with something unique to your situation (Size, FileSystem, etc).

One final note, due to the use of the virtualization WMI namespace, this code will only work on Windows Servers that have the Hyper-V Role installed. With the announcement that Wndows 8 is getting Hyper-V I am hopeful that the WMI virtualization namespace will become available to client OSs as well!

Advertisements

January 16, 2011

No I am not going to blog about my cats

Filed under: Life in general — Devlin Bentley @ 11:46 pm

Yes I have two kitties, no I am not going to turn this into a blog about weird things cats do. That is what Facebook status updates are for.

(yes they are cute)

September 21, 2010

The commoditization of the Smartphone Market

Filed under: technology — Devlin Bentley @ 10:43 am

(Note:  I am no longer an employee of Microsoft nor am I in any way at presently related to either Windows Phone or Windows Mobile.  All opinions expressed here are mine and mine alone.)

A Nokia Executive recently said that phone manufacturers using Android is “Like peeing in your pants to stay warm.”  The implication there being that over the long-term the manufacturers are just hurting themselves.

He is correct.

In the long-term, using Android or Windows Phone is a doomed strategy for the phone manufacturers.  The executives of these companies (HTC, Motorola) know this, but they really have no other choice.

For many years now Microsoft has been trying to repeat their successful desktop business strategy in the smartphone market.  As a quick refresher, their desktop strategy was quite simple: 

  1. Make a highly usable desirable OS, licence it to computer OEMs to sell with their machines.  This means all computers sold by different manufacturers will be, to a large extent, identical underneath the lable.  Minor HW differences aside, consumers will desire a “Windows” computer. 
  2. Competition between manufacturers will drive down price, thereby increasing the number of people who can afford to buy a computer, encouraging more manufacturers to enter the market, further driving down prices.  Rinse, wash, repeat, after about two decades an entry-level computer now costs $200.

If you are an OEM though, there is a nasty side effect: The profit margin on a new computer is almost $0.  On lower priced machines those annoying sponsored apps that come pre-installed are often the only way companies like Dell and HP make a profit at all.

Initially things weren’t so bad.  Companies such as Dell and HP had a healthy profit margin.  It was when the first round of drastic price cuts hit in around 1999 that you saw companies like Gateway[1] pretty much cannibalize themselves to stay alive.

Microsoft has been trying to apply this same strategy to the smartphone market for nearly a decade now.  When the smartphone OEMs looked at what happened to Dell and Gateway, and then looked at Microsoft’s offer to take Windows Mobile to the masses, they basically said “no thanks”.   OEMs put the minimal effort needed into selling Windows Mobile to business customers and they never dedicated the resources to it that Microsoft was hoping they would.  After Palm’s initial dropping out of the smartphone market, OEMs stopped competing at all.  Hardware, prices, screen size, resolution, all stayed the same for years. This pleased the OEMs, Smartphones stayed a niche high margin market, being bought by businesses and tech enthusiasts.  Eventually an excuse for the static growth of the Smartphone market appeared: “Consumers do not want to buy smartphones”. Eventually both the OEMs and many within Microsoft started to believe in this excuse.

Apple changed all of that.  Apple demonstrated that you can sell Smartphones to everyday consumers, and pretty much mint money in the process. On some of the earlier iPhones Apple was making over $200 profit per phone sold.  That type of profit margin on technology is just insane.

What happened next was predictable. Everybody starting ramping up Smartphone manufacturing.  Unlike Apple, they are using commodity OSes, either Android, or Windows Phone.

And now they are all doomed.

Right now smartphone OEMs are competing on features.  Resolution, processor speed, memory, storage, camera resolution, screen quality, are all increasing while prices are staying the same.  Phone OEMs are desperate for new features to add to justify keeping prices up, just look at all the buzz about dual core ARM processors that are “coming soon”.  But no matter how hard the OEMs struggle, prices will begin to fall as features level off. 

And the history of the PC market will finally repeat itself.

Microsoft has been working towards this for years.  You have a bunch of really smart people who see the potential of technology, and they have been trying to get that technology out to the masses for over a decade now.  Apple demonstrated that the market is there, Google came along with a shinier OS that is popular right now, but no matter which company ends up winning the mobile handset OS race the overall lesson is that history is going to repeat itself. Prices are going to drop, and OEMs are going to have smaller and smaller margins on handsets.

The phone OEMs know this.  They don’t want it to happen.  The smarter executives see the writing on the wall and are making money off it while they can, the foolish ones may actually believe the current state of affairs (having a profit margin to speak of) is going to last.  It won’t. 

As for Apple?

After a brief flare of massive profitability they will once again fade to being a niche player.  History repeats itself.  They cannot maintain their insane profit margins for much longer, once features level off Android and Windows Phones are going to start to drive down the average cost of smartphones. Apple will either have to lower their prices to compete or once again become relegated to being a high-class luxury brand.

[1] In the mid 1990s Gateway had a reputation for having the best customer service, something I can personally attest to.  My $2000 Gateway computer came with in-house tech support, when something broke a tech guy came and swapped the broken part out. When the price cuts hit Gateway pretty much destroyed their customer service reputation, it has taken them many years to rebuild it.

July 28, 2009

Focus Bracketing On My Consumer Digicam

Filed under: Life in general — Devlin Bentley @ 4:16 pm

So long story short, I installed CHDK on my $300 Canon digicam (SD880).  I only get 1mm control over focus, but it still allowed me to produce this cool picture:

WinCE Dev Board

WinCE Dev Board

I put it together using the free CombineZP application.

July 11, 2009

My New PC

Filed under: Hardware Review, technology — Tags: — Devlin Bentley @ 3:17 am

Waiting for Brown

On days like today I think UPS is worse than Santa for one single reason:  Santa does not taunt you with a tracking number.

Yes, Friday was a day spent waiting for UPS to come and delivery goodies in boxes, boxes containing many parts, and with much assembly required.

Though personally I happen to think that the end result looks rather good

Front of Case Power Off

Devlin's PC Build 2009 042

But getting there was not as easy as it should have been.

Of course, where are my manners, first the technical specs for those of you who care.

Geek Specs

CPU: AMD Phenom II X4 905e 2.50GHZ (energy efficient 65 watt version of the quad core 2.5GHZ Phenom II)
Motherboard: Asus M4A78-EM MicroATX
Video Card: HIS ATI HD4850
RAM:  8GB DDR2 PC1033
Primary HD: OCZ Vertex 64GB SSD drive.
Secondary HD: 250GB drive from previous machine
Case: NZXT Rogue MicroATX Silver (Brush Aluminum)
Power Supply: Some crazy Antec unit I probably paid way to much for
OS: Windows 7 RC

Naturally everything except the power supply and OS was purchased on Newegg.com.

Until about half an hour after first boot I thought the SSD drive was a waste of money.  Since then I have had continuous issues involving picking my jaw up off of the floor.

NZXT Rogue Review

This is, no doubt about it, a very lovely case.  On sale for $80, it was a very affordable, lovely case.  Of course three days after I bought one its sale price has been dropped by $10 down to $70 but such is life in the world of technology.  My CPU is also $5 cheaper now.  🙂

In spite of its good looks, this case, as many of the Newegg reviews hint at, has some issues.

Getting the Case Apart

I have never had to remove so many screws to get a case apart.  It must have been around 10 screws total to get to the hard drive cage.  This also counts removing the motherboard tray, since builds with this case must be done in a very particular order or else you will find yourself stuck.

In the past I have built many computers where the hard drive/CD-ROM drive mounting cage eloquently popped out of the case, I slide my drives in, threw on some screws, and popped the cage back into the case, and went on my way.  This case is nothing like that.

Granted few MicroATX cases allow removal of the drive cage once other components are in place, but even so a removable drive cage would have shaved at least an hour, if not even more, off of how long it took to do the initial installation of components into this case.

The 1 Hour DVD-ROM Drive Install

Let me put a disclaimer in here and say that I have built many, many, PCs.  I have done quite a few years of lab work at various times in my life, in addition to building PCs at home. Going at a good clip and after I get into the rhythm of things, in an hour I could install a dozen plus DVD-ROM drives.

This case aims to adjusts one’s expectations in a rather downward direction.

I am guessing that my DVD-RW drive just so happened to be a fraction of a millimeter too wide to fit when using the included drive rails.  Abandoning the rails I tried to screw the drive in, but the screws that had secured the drive in its previous case would not reach due to the layer of sound dampening material that lines all the drive enclosures.  All the drive enclosures are a little wider than normal to make room for the sound dampening material, so normal mounting screws do not reach.

If you add together how long it took me to unscrew my way to the drive cage and how much pushing and shoving I had to do to get the drive into place, it was at least an hour to get a single DVD drive installed.  It was immediately after declaring success that I noticed NZXT’s included bag of "”CD-ROM screws” happened to be a bit longer than typical 5.25” drive mounting screws, such as the ones I had failed to use.

I have a box of 5.25” drive mounting screws (as a subset of my larger “computer screw box”).  They are all the same thread pitch, same length.  The screws used in this case are not.  I can’t fault NZXT for having sound dampening material in their case, quite cases are good cases, but unusual screws are, well, unusual.

Tin Foil Motherboard Tray

If the metal used for the Motherboard tray was any thinner, it would qualify as tin foil.  I do not think I have ever seen a piece of any computer case that was so easily deformed, and I have repaired a lot of cut rate computers. The thinness of the metal was quite surprising given that

This Thing Weighs a Ton

Ok not a ton, but the case does weigh around 20 pounds.  Much to the amusement of reviewers, NZXT advertises it as a portable LAN party case.  Thankfully I did not buy it with any intentions of taking it to LAN parties, but the included carrying strap (carrying harness?) is all the more hilarious for thoughts of what would happen to anyone’s back if they pretended that this case was portable in any sense of the word except for “not nailed down”.

To make it clear, I am not criticizing the case for its weight.  I wanted a case made of brushed aluminum and I got it, and I am much more pleased with it than I am with the “brushed aluminum door cover” style case that I purchased previously.

However I do find it amusing that my MicroATX based computer, weighing in at 31LBs total, feels like it is just a few pounds shy of my full tower case, which has yet to be formally weighed.

Seriously, this case is unexpectedly heavy.  I am still not quite accustom to the idea of such a small computer weighing so much.

More Complaints about Assembly

This would be a really good case if assembly wasn’t so evil.  Of course not that many cube’s have a total of five 3.5” bays, (four internal, one with an external facing), but actually installing anything into the drive cage is a very convoluted process.  A good example of this is how installing any 5.25” device first requires removing any installed 3.5” devices, as can be clearly seen in one of Newegg’s promotional shots:

NZXT Cube Newegg Drive Bays

Notice 3.5” drives are mounted vertically next to the 5.25” bays.

Thankfully I read the manual first which clearly warns users to install any 5.25” drives first.

Speaking of the manual, the pictures are either so poorly taken or poorly printed as to be universally too dark and it is indistinguishable which part of the case is being shown in any of the (far too few) photos.

Lots of Bags

Many bags of screws, all very well labeled.  Awesome job on this.

What’s Up With The Fans?

None of the chassis fans use smart fan plugs, instead they all opt for Molex.  I can understand the fans with LEDs perhaps needing more power, but the side fans could stand to have proper speed controlled monitored plugs on them.  Although I must admit one very awesome thing about the fans is that

The Fans Have Filters

Fan Filter on Side Case Panel (repeat for other side panel)

Except for, you know, the huge fan in back which just has a standard useless grill

Rear Case Fan

If the 3 included case fans are not enough, it is possible to install 2 more fans, 1 on each side of the case.

Well it would be, almost.

Where Are The Rest Of My Washers?

Case Side Fan Washers

NZXT installs filters on the two spare fan slots, but only includes enough washers for one more fan.  This confuses me a bit.

Other Build Issues

My front USB ports are busted

Broken Front USB

The top port does not work at all, Window’s does not recognize when something is plugged into it, while anything plugged into the bottom port results in the error “A USB Device Has Malfunctioned…”

Yes, I’m a little pissed about this.  Come on folks.  20 lbs of brushed aluminum and you skimp out on the build quality of the front USB ports?  Even the internal header is flimsy! (Admittedly in my experience internal USB headers on cases are always rather flimsy.)

The plastic top window also looks like a layer of it is peeling away

Top Window Peeling

I apologize for the quality of the picture.  Apparently to my digital camera the case’s top window is just slightly more reflective than a mirror.

It actually looks a fair bit worse in person.  At first I thought it was another protective layer of plastic wrap, but it is something internal to the plastic window itself.

Neither of these issues is going to get me to RMA the case, mostly because of how hard it is to put together.

Other Thoughts

I have no internal cable running skills

Internal Cable Nest

This is why I did not want a case with a side window.  :)  After 20 more minutes of attempts at organizing the cables the situation did not improved by much.

The Motherboard has PCI slots.  I have no clue why.  I would much prefer another PCIe 16x slot so I could put another 4850 in here next year when they’ll be going for $50 a piece.

SSD drives are fast.  I read about it being like “night and day” but of course I didn’t take it seriously.  I do now.

Overall Performance

REALLY DAMN FAST.

Apps install so quickly it is insane.  The system boots so quickly it is crazy.  This BIOS has a “fast on” feature where it can boot to some minimal OS ASUS provides.  This “fast” boot time is 10 seconds.

Why bother when I can wait 15  and be into Windows?

July 31, 2008

ZIPing a self extracting ZIP does not make it smaller

Filed under: Stupidity, technology — Tags: , — Devlin Bentley @ 10:28 am

I have been witnessing the stupidity of people putting their self extracting ZIP files into a ZIP file for years now, and it still pisses me off.

If grouping files together then ZIPing them up in “no compression” or “archival” mode may be useful, but that is it.  A single lone file?  Pointless!  (And yes, I will explain why at the bottom of this post!)

Here is a list of other things that do not belong inside of ZIP files:

  • Any other compresses sound or video file
    • MP3
    • AVI
    • MPEG
    • MPEG2
    • WMV
    • etc
  • Any file already compressed with another compression program
    • JPEGs
    • RAR files
    • .ACE files
    • .7z Files

The reason for this is actually easy to understand.

Imagine taking a piece of paper and folding it up really small so you can fit it in a really tiny envelope to mail off.  You fold the paper up as small as you possibly can, and put it in the envelope.  The paper is your original data file and the envelope is the ZIP file.

Now imagine trying to take that envelope with your paper inside of it, already folded up as tight as possible, and putting it inside another envelope.  You cannot fold the paper any more, so nothing is any smaller.  In fact by adding another envelope you have actually made your package larger!  It is only a little bit larger because an extra envelope is not all that thick, but it still is larger.

This is exactly what happens when you try to ZIP a ZIP file, or any other type of already compressed file.  In some cases when you ZIP up a compressed file of some other type (e.g. JPEG) you may save a little bit of space, typically a a kilobyte or two if it is a really huge image that is in the megabyte range, but the time it takes users to open up the ZIP file and hit ‘extract’ is longer than it would take them to download the extra few kilobytes.

This seems like only a minor annoyance, but it because a huge pain when some fools who should know better put huge 2GB+ self extracting game demos inside of a ZIP file.  They save maybe one megabyte overall (if even that), but it can take 15-20 minutes to extract their stupid EXE, which then takes another 10-15 minutes to extract the installer.

Bonus points go to the real idiots who do all of the above, and then their installer is itself a single compressed setup.exe when when run then extracts files to a temporary directory before copying them to their final location.

2GB ZIP -> 2GB self extracting EXE -> 2GB Setup.exe -> 2GB temporary files -> 4-5GB installed game

And that is why the tag stupidity is on this post!

December 31, 2007

Towne Pointe Pulls Listings

Filed under: Life in general — Devlin Bentley @ 3:14 pm

Towne Pointe, the very nice (if someone traditional) condo project just a stones throw away from downtown Redmond, has either taken down almost all of their listings or have sold all of their remaining units (spare one) over the holidays.  For posterity, and in case things change, I have captured a screen shot of Condo Compare’s listing for Towne Pointe units.

image

It is interesting that more and more agents are just completely pulling listings down.  Relisting houses and condos is of course quite common (though annoying from the buyers perspective), and it will be interesting to see if Towne Pointe relist their units sometime soon, e.g. before the “spring rush”.

Of note, Towne Pointe has not sold any units since August 2nd (and I would really consider that a July sale), as can be seen in the King County Records for the complex.  Simply checking the sold date on each unit shows they had a burst of sales between June and July and have had nothing since, a story that many real estate agents are becoming familiar with.

Note:  Some portion of King County’s website is down right now (3:34PM Dec 31 2007)

December 29, 2007

The Cleveland

Filed under: Life in general — Tags: , , , , — Devlin Bentley @ 7:15 pm

My girlfriend Lila (who already has an excellent post about The Cleveland) and I went to visit The Cleveland in person today.  It was late in the day, raining, and we had just finished up visiting another project.  Still, we learned some valuable information and got to see the room layouts in person.  I have to say that they look bigger in person than one imagines from the floor plans. 

After coming back home, we again went over the numbers we had gathered about The Cleveland, looking for some more patterns or discrepancies.  Comparing the price of identical floor plans on the resale market to that which the builder is selling, we found something that makes perfect sense but still made us quite peeved.  The two prices are identical!

  1. Let us compare units 513 and 506, identical floor plans on opposite corners of The Cleveland.  Looking at the sales history for unit #513 and the asking price for unit #506, we see that unit #513 sold for $394k in early July, and was then resold for $467k.  The price the builder is asking for #506?  $467k!  Yet obviously anyone could have gone there back in July and bought it for around $394k.

Normally this would seem like common sense behavior, if you sell something for X, and the guy next store can sell it for X+1, you need to raise your price, you are selling too low.  But this is not the situation with condos right now, instead I would argue that the $467 price was inflated by a bubble and that the original price should still hold true.

The lesson here is to always do your research and to be an informed buyer.

December 9, 2007

Why is there Carpet in my Dining Room?

Filed under: Life in general — Tags: , — Devlin Bentley @ 8:39 pm

dynamic_imageCAZBJW7O

Not naming names here, because a ton of condos do this.

At least the unit posted above does not have white carpet in the dining room area.  I have seen what happens to white carpets in dining rooms, and it is not good.

Also, any chance I can get some cabinets made in this century?  Thanks!

Dumb Plans Post 1: Trio Seattle

Filed under: Life in general — Tags: , , — Devlin Bentley @ 8:24 pm

One danger of looking around at condos is that one will inevitably lose their faith in humanity as they see stupid floor plan after stupid floor plan take up precious human living space.  Even scarier is the knowledge that someone will buy these units, not knowing any better, and have their quality of life decreased by living in a poorly designed space.

The first such example I will post is from Trio.  To be fair, Trio has a number of good floor plans, but the following is not one of them:

image

The first item that is noticeable about this 1×1 condo is the size of it: almost 870 sqft!  When I first saw this, I was sure it would have a den or office somewhere in the floor plan.  Unfortunately I was quite disappointed when I looked closer.  What could have easily been a luxury 1 bed 1 bath unit has instead turned into yet another waste of space in Seattle.  I admit that this floor plan might be perfect for someone with a large art collection they want to show off, but otherwise it seems to me that the huge entrance area is wasted.  I have to keep asking myself:  Who thought that a 1×1 condo needed a foyer?

As for fixing this mistake, I guess some portable walls could be put up to make something resembling a den.  For a buyer who doesn’t care, it is always an option to have their computer, bills, papers, and office supplies be the first thing to greet visitors stepping into to their home, but for anyone else, a properly secluded home office or den is appreciated.

I also cannot understand that laundry room.  How much dirty cloths can one or two people have?

Even sadder are the possibilities of what all that space could have been used for.  Instead of the entrance being taken up for sheer nothingness, the bathroom could have been extended and possibly had a full 5 piece bath set installed.  in the least, dual sinks or a large Jacuzzi style tub could have been put into place.  The bathroom could be also be shifted down a bit and the large walk in closet enlarged.  Making part of the laundry room into a nook is a potential use for it, but paying bills or writing blog entries is not going to be easy when sitting right next to a running washing machine or dryer.

Part of the units problems are due to lighting.  Because there is no way to get light to the back of the unit it is not feasible to place a second bedroom anywhere.  On the other hand a den or office does not require the same lighting that a bedroom does.

Trio Seattle

« Newer PostsOlder Posts »

Blog at WordPress.com.