James O'Neill's Blog

September 30, 2009

My life in a bag

Filed under: Uncategorized — jamesone111 @ 7:59 am

I have became a crime statistic.
It was only a bag. And I didn’t realize the significance it had until it was gone. Jerry gave out laptop bags as a thank you: working with him and that group of people was the best aspect of that stage of my life, so the bag itself embodied a happy memory. On one of my diving trips it picked up a sticker going through security; I never peeled it off and that too was a reminder of happy times. My web cam lived in the front pocket – Peter gave me that as a thank you for helping out on a Unified communications tour in Asia: just being asked to do that made me feel like I was someone again after my self-esteem had taken a pounding. I gave away better webcams because I liked having that one with me. My presenter mouse lived beside the webcam and that too had been a thank-you gift. Was it Slovenia? or was it Belgium? Both involved crazy travel and I’m sure both gave me the mouse with a laser inside. I gave one away as a prize and kept the other – which reminded me of both trips. In the top pocket was a collection of USB connectors I’d built up of the years, a set of headphones with a bullet mic I’d picked up at one of our events and the comfortable headphones which I’d had for 4 or 5 years.  Then there were memory sticks – I’ve never bought one and each of those had their story.

In the main pocket was my laptop: a 2 ½ year old Dell which had seen better days. I care less about the thieving bastards getting that loyal old workhorse than the sticker on it saying “well done”. That came from a supply teacher at my daughter’s school: she had expected to find PowerPoint on the computer in the classroom but it wasn’t there, and I conjured up a copy of the PowerPoint viewer: another good memory. And I’m cross as hell they got the memory card from my camera which was still plugged into the laptop. I’m not sure which pictures were only on the laptop or the card and nowhere else: those memories are gone.

What makes me crosser still is the vermin took my fleece. It was a crappy give away fleece: I guess they were hoping for something in the pocket – my battered old phone wouldn’t have been worth much, but I had that with me, along with all my cash and credit cards. They got my keys, which is pretty inconvenient (as I typed the draft of this, a locksmith was getting to work just in case they work out where I live – replacing car keys is even more hassle), but in the other pocket was my Microsoft security badge. If you’ve seen me wearing my badge there’s about 50:50 chance you saw the side which said Yoda. Lorie got those badges for a group of us who were known as her Jedi. It was a talking point, an ice breaker, and yes, the embodiment of a memory. A little oblong bit of cheap plastic is really the thing I’m most upset about losing.

Moral of the story ? There isn’t one really. Even at Microsoft event someone can walk in and steal something while your back is turned… Using bit locker reduces the data risk in these cases … the thing that amazes me is how much of my life was in one bag.  I wish I could adapt that Shakespeare quote about stealing someone’s good name , the one which begins  Who steals my purse steals trash; ’tis something, nothing; ‘Twas mine, ’tis his, and has been slave to thousands; but I can’t. I just needed to write about that sense of loss. Thanks for reading.

tweetmeme_style = ‘compact’;
tweetmeme_url = ‘http://blogs.technet.com/jamesone/archive/2009/09/30/my-life-in-a-bag.aspx’;

This post originally appeared on my technet blog.

September 28, 2009

Hello Exchange 2010

Filed under: Exchange,Real Time Collaboration — jamesone111 @ 3:52 pm

Inside Microsoft we have this custom of “dog-fooding” new software, and Exchange 2010 is now at the point where Microsoft IT feel they can run it outside of North America. So a few days ago I got a mail saying my mail box was going to be moved to a new server “using the new Exchange 2010 Online Mailbox Move feature, which means your mailbox should not experience any downtime during the migration.” It’s 3 years since I moved away from being an Exchange consultant and so I’ve not kept track of exactly how it handles storage better, but it does, so the move to 2010 is giving us 4.5 GB mailboxes instead of the current 1GB, so I shouldn’t need to empty my deleted items folder before the end of the year.

Before leaving for the office this morning I checked my calendar with Outlook Web Access and I was still on 2007. I got to work and Outlook told me to log off and log on again because of a change, and there was a mail saying my Voice mail had a new PIN a new access number for 2010. Outlook 2010 has a little status box in the corner telling me how near to full my mail box is, that was still reporting that I was down to the last of my space. Then at a few minutes past 11 I noticed that box had gone. I re-enabled it and woo-hoo I had a 4.5 GB mail box. As a user the Online Mailbox Move lived up to its billing. Something might have hidden some downtime from me, but the move didn’t appear to happen while I was driving into work and I didn’t see any down time. When things go badly with our internal IT, “Microsoft IT” gets a lot of flack: when things go this well, they look like heroes.

2010 gives me an update to the Unified communications bits, notably it transcribes voice mail – the jury is still out on how well it will do that overall, but you if you pick up mail on a mobile device you get some sense of the message without having  to dial in or download the sound file. With Exchange 2007 I’ve grown used to being able to call in and get my e-mail read to me and I’ll be interested to see  if 2010 copes better with bad mobile phone connections and still does some of the slightly comical translations of  internal abbreviations “MS” becomes Manuscript, and “Technical Sales Professionals”, TSPs in Microsoft speak were teaspoons. Someone whose initials are SJ let us know that this got translated to “Society Of Jesus”. 

This morning we also got chatting in the office about our use of the full unified communications suite. This means we have our own voice conferencing system based on Office Communications Server (so no need to spend money on 3rd party dial up conferencing services), and we can use Communicator as a soft-phone when travelling or working from home. The former means cheap calls from abroad, and the latter give me a workround or the patchy phone signal I get at home. I love UCs call routing abilities – or perhaps I should say I hate putting people through the dilemmas of “Do I call this number or that number” and “If I get voice mail, should I redial on another number”. So I give out one number: UC will simultaneously “ring” on my PC and on my mobile and I can answer from either. If I’m at my PC I can steer the call to a different number or to voice mail, and it’s easier to forward the call if need be (even forwarding it to my mobile so I can shut the PC down and walk and talk). The only caution here is setting communicator to “Do not disturb” routes all calls straight to voice mail: forget to take communicator off DND you get voice mails without the phone ringing.  I need to educate people “Yes you can have my mobile number to text me, but if I don’t answer on the landline number, there is no point ringing the mobile.” , “If you do ring the mobile and get no answer you’ll will have to ring the land-line to leave a message”.  No-one seems to have got a good way to tell who is more easily contacted by mobile for whom the “one number” is not the desk one but the mobile: everyone assumes the numbers they give out themselves are the best numbers to give out for other people.

tweetmeme_style = ‘compact’;
tweetmeme_url = ‘http://blogs.technet.com/jamesone/archive/2009/09/28/hello-exchange-2010.aspx’;

This post originally appeared on my technet blog.

September 27, 2009

Windows 7… “Media for everyone !”

Filed under: Music and Media,Windows 7 — jamesone111 @ 8:12 pm

From the betas of Windows Vista until the start of September I ran the Ultimate edition of Windows, rather than the enterprise edition. We had a perfectly good enterprise edition as a network installation, but in Vista there one some features missing from enterprise and from time to time I needed to talk about those. I never quite understood the thinking that video never needed to be edited in a business context.

A check of the version comparison page shows the way things have have changed for Windows 7. Professional is a super-set of Home Premium; Enterprise and Ultimate are effectively the same super-set of professional, just with different licensing. So Media Center and so on are in the versions found in business. I don’t see many IT departments thinking “oh great we’ve go Media Centre on every PC” for desktop PCs in the office you might turn it off (via Windows features in control panel). But think of the road warrior carrying a laptop round the country: plug in a USB TV stick (I have one from Hauppauge but there are others out there – prices now start at under £20) , and all the Freeview (or other DVB-T) channels are watchable from a hotel room or wherever: so is anything recorded on Media Center at home

Like quite a few things Media center has been given an additional polish between the Windows Vista an Windows 7 releases : for example it colour codes different program types, and for movies on TV it will also pull down a miniature of the movie poster. The movies menu shows all the upcoming movies with their posters.

Click for a full size version Click for a full size version

During the beta I discovered “My Channel logos” : it changes the text for the channel names with their logos which you can see in the left picture: well worth the $3 donation the student who created it is asking for I’d say.

This post originally appeared on my technet blog.

September 23, 2009

On Scanners, Cameras and their USB modes, and lifting the lid on how they can be scripted.

Filed under: Photography,Windows 7,Windows Vista — jamesone111 @ 11:46 am

Long title, and I’m afraid I’ve been on a bit of a voyage of discovery about some of the things Windows 7 (and Vista) can do with photos and first thing I wanted to cover here was something I’ve been trying to ignore: Cameras have two USB modes.

In “Mass Storage Class” (MSC) mode, the computer sees the storage card with its blocks and filesystem and so forth like any other disk. Since the computer can write to the disk all kinds of problems could break out if the camera tried to access the disk, so when  connected the camera functions need to turn themselves off. In MSC mode the camera is becomes a USB card reader and acts like any other USB disk. (That’s the point of MSC devices)

In “Picture  Transfer Protocol” (PTP) mode – and its superset, the media transfer protocol (MTP) – the camera acts as a server – the computer requests a list of files, properties of files, contents of files, but it has no access to the underlying file system so the camera can continue to take pictures and write to the disk. This offers the chance to shoot and have the PC interact with the camera at the same time,  provided that the camera maker doesn’t shut all the functions down when connected in PTP mode. Sadly Pentax do; I put my wife’s Panasonic compact in PTP mode and it was the same. On my the little Canon I take on diving trips there is no “PTP mode”, but it does have Pictbridge support. PTP is the transport protocol for PictBridge and enabling pictbridge got it to work like the Panasonic and Pentax – i.e. all the controls are locked out. From what I’ve read Olympus are the same. Of course I haven’t got the information for every camera made by every manufacturer! I’ll come back to this towards the end of the post, but it changes the way your camera appears…

Click for a full size image  Click for a full size image  Click for a full size image    Click for a full size image

From left to right with my Pentax K7 in PTP mode the camera doesn’t show up as a drive, but as a portable device in Explorer. (I could have used the Canon or Panasonic here).  When you look in the devices and printers part of control panel of Windows 7 you see the camera. If you click through the K7 here gave options to browse, import or configure options. Something which seems different to the other cameras is the option is to automatically import photos when it the camera is plugged in (The K7 does not disappear when unplugged which all the other cameras did.). Not every imaging device which shows up in control panel is a WIA device. In the screen shot below you can see I’ve unplugged my K7 – the icon is greyed out – and plugged in my Web cam; which doesn’t show up in WIA.  The reverse is also true – there is a WIA driver for Windows Mobile devices, but my phone doesn’t show up in devices and printers (at least not as a phone or a camera, only as a potential networking device) but it does show up, with a phone icon, under Portable Devices in Explorer where it has access to the same photo import wizard that the cameras have.

Click for a full size image

Linked in with this there is a Windows Image Acquisition (WIA) driver for PTP enabled cameras – so you can fetch pictures from the camera in a program which understands scanners. Generally, programs that were written for WIA will talk about “Scanner or Camera” – as in the screenshot from Windows 7’s version of Paint below, although WIA allows a program to restrict its choice to scanners only or cameras only. (Windows Fax and Scan won’t accept camera input, for example).  WIA also provides a translation layer to support programs which were written to the older TWAIN interface: these usually talk about acquiring an image from a scanner. When a device appears through the translation layer its name in the TWAIN world is prefixed with “WIA”. Some scanners include both WIA and TWAIN drivers – though the TWAIN ones are redundant on Windows Vista and 7 – and in which case the scanner gets two entries in the TWAIN dialogs (one with WIA in front of the name and one without).  I’ve got a bad track record choosing scanners and the latest piece of junk I’ve bought has a WIA driver which does not work and a TWAIN driver (which does). Hunting down the 64 bit drivers was an undertaking in itself, and for reasons only known to the scanner driver writer it appears in some dialogs when it is not plugged in. [I could go off an huge rant here, at least my ancient HP scanner has a driver on Windows update, although it doesn’t support “Transparent Materials Adapter”, so I bought this one to scan film. How hard is it to produce a driver which works properly and supports full functionality of the scanner? Why are scanners, and cameras bundled with so much useless application software to provide things like “browsing pictures” less well than the OS does it when the vendor can’t get the basics right ? OK enough ranting….] So here in Paint my new film scanner appears alongside the K7. Any attempt to use that driver will fail…grrr… but my old scanner (in page scanning mode only) or the cameras or smartphone will transfer images straight into the application.  

Click for a full size image Click for a full size image

Click for a full size image

The oldest piece of software I still use is Paintshop pro 5 (dated 1999) and it uses TWAIN. In the left picture you can see that it sees the translated K7 WIA driver and the TWAIN driver for the scanner (which isn’t plugged in). Unplug the K7 and plugging in the scanner and the dialog presents the options on the right – with WIA translated and Native TWAIN drivers – only the latter works.

Click for a full size image Click for a full size image


It’s possible access scanners and cameras from a scripting environment. I’m not going to advocate that everyone transfers pictures via PowerShell but it can be useful for diagnostics purposes. You can pop up a PowerShell prompt and enter the following

  PS > $WIAdialog = New-Object -ComObject “WIA.CommonDialog”  
  PS > $Device    = $WIAdialog.ShowSelectDevice()

If I do this with no camera or scanner connected I get this error :

  Exception calling “ShowSelectDevice” with “0” argument(s): “No WIA device of the selected type is available.”

But if I do it with the rotten scanner connected I get this:

  Exception calling “ShowSelectDevice” with “0” argument(s): “The WIA device is not online.”

Assuming the commands is successful one can dig a bit deeper into the properties of a scanner or camera – I’ve cut the list down a little to save space.

PS > $device.Properties | sort name | format-table –autosize propertyID,name,value,type,isreadonly                                                                                             

PropertyID Name                   Value                Type IsReadOnly
———- —-                   —–                —- ———- 
         4 Description            K-7                    16       True
      1028 Device Time            System.__ComObject    104       True
        15 Driver Version         6.1.7600.16385         16       True 
      1026 Firmware Version       1.01                   16       True 
         3 Manufacturer           PENTAX                 16       True
         7 Name                   K-7                    16       True
      2050 Pictures Taken         419                     5       True 

As well as the properties collection, the device has an Items collection, which contains the pictures currently in the camera. Here’s the view of one item.

PS > $device.items.item(1).properties | sort name | format-table propertyID,name,value,type,isreadonly –autosize

PropertyID Name                             Value Type IsReadOnly
———- —-                             —– —- ———- 
      5125 Audio Available                      0    5       True
      5127 Audio Data          System.__ComObject  102       True 
      4110 Bits Per Channel                     8    5       True
      4104 Bits Per Pixel                      24    5      False 
      4109 Channels Per Pixel                   3    5       True 
      4123 Filename extension                 JPG   16       True 
      4099 Full Item Name               o506400A5   16       True 
      4098 Item Name                     IMG40165   16       True
      4116 Item Size                      6663701    5       True 
      4114 Number of Lines                   3104    5       True
      4112 Pixels Per Line                   4672    5       True

As well as having methods to work with the item, there are two useful wizards. The first one pops up a scanning wizard – if a plug in my other scanner, and it will automatically save pictures in a folder under My Pictures – the folder is created with the current date.


And the second will work with scanners or cameras and returns the image as an object which can be manipulated before being saved


The last things about the device object which I wanted to mention were the Events and Commands, properties. The Pentax and Canon both have events which a script can watch for to respond to changes in the files stored on the camera. This is would be useful on cameras which didn’t lock out all the controls while connected – because that means the files can only be changed from the computer end. Similarly on all three of my cameras the list of commands is disappointingly small. 

PS > $device.commands

CommandID                                Name            Description       
———                                —-            ———– 
{9B26B7B2-ACAD-11D2-A093-00C04F72DC3C}   Synchronize     Synchronize


But on some cameras there are more commands , including one named Take Picture, which has an ID of {AF933CAC-ACAD-11D2-A093-00C04F72DC3C}
I can’t test this myself (one blog I found seems to be looking for cameras which do support it, among other things) it seems NOT having the controls locked out is a pre-requisite for this. If it shows up on your camera (and it seems to be mostly Nikons which support it) you should be able to take a picture and acquire it with

$I = $device.ExecuteCommand(“{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}”)

and save it as in the previous example.  [Anyone who wants to post a comment about cameras where this works (or not) would be most welcome]

I’ll come back to WIA and some of the related technology in a future post, but that’s quite enough for now.

This post originally appeared on my technet blog.

September 20, 2009

Story of a photo.

Filed under: Photography — jamesone111 @ 11:46 am

Click for a larger versionMy last two working days were spent at a team “off-site” – and these things tend to bring out the curmudgeon in me (as I’ve said before). Past experience sends me in braced for a combination of people mumbling their way through 10,000 word PowerPoint decks on their subjects, prepared without a moments thought about what the audience might be interested to hear, and the kind of “organized fun” which makes one wish one had booked a visit to the dentist.

This weeks event stated with Giles Long, a swimmer who won Gold medals at two paralympics. I don’t think it’s overstating things to call him brilliant. He is working as an ambassador for the 2012 games – and if he weren’t I say they should sign up for the job.  Come the evening, we had a  second guest speaker before dinner. It was Terry Waite. I realize that if you’re reading this from outside Britain you might need look him up on Wikipedia. A remarkable man, with a remarkable story to tell, and a style of delivery to do it justice. I can’t remember seeing an audience so completely spellbound. I’ve seen people hang on a speakers every word, but it was always punctuated with laughter or applause, saying a speaker was “heard in silence” normally implies a background of shuffling and fidgeting, but not here. For over an hour you could have hear a pin drop. It’s rare to feel that something work sets up is a privilege but I wasn’t the only one who felt that way.

This post is not meant to be a critique of the idea of off-sites, or even the story of how my expectations got turned on their head at this one, but to be the story of this picture. I was asked to take my camera and had the new Pentax K7 with my 18-250 Zoom mounted on it : this lens is a bit of a Swiss Army Knife: very versatile, but there are some jobs which require the right tool. I snapped a few pictures at the start of Terry’s speech, but wasn’t happy with them. My other lenses were in the car: leaving the room to fetch one might have seemed rude, and anyway I didn’t want to miss what was being said. When he sat down I dashed down out and fetched my  Pentax 77mm f/1.8 limited lens. Those who know reckon the Pentax limiteds are the best autofocus lenses ever made (owners just smile when people mention Canon’s “L” glass). I needed the extra speed because because the venue turned the lights down, and using flash would just look horrible, as well as being intrusive. Very low levels of artificial light tax an autofocus system and the K7 doesn’t have much in the way of manual focus aids, yet with very little depth of field to work with the focus has to be pretty much perfect. With the slower zoom lens the amount of light getting in would be less than the autofocus system needs to work – the K7 does have a focus assist lamp, but that that’s intrusive too. 

As well as letting more light in, with the crop factor on a digital SLR, the 77mm is ideal for the semi-candid photos I wanted: when someone is your guest it seems wrong to be shoving a camera right in his face. In fact I cropped the picture giving something more like a 180mm lens’ view on 35mm film. Even at an ISO rating of 1600 and an aperture  f/1.8 it needed a  1/25th second exposure – which would be hopeless without the K7’s in-body shake reduction. (I may be wrong on this, I don’t think anyone makes a stabilized, fast prime at this focal length: Putting stabilization in the body –as Pentax, Sony and Olympus means every lens stabilized which is a real winner at times like this.) Even so it’s not perfectly sharp and the high ISO is noisy – more so because of the cropping. But it’s a picture I’m mighty pleased with.

In converting to monochrome I’ve tweaked brightness and contrast slightly and just given a hint of warm toning (my technique is to set a colour which is noticeable, and then halve the amount). I haven’t applied any noise reduction or sharpening. – though I might when I come to print it (I might split tone it with warmer whites and cooler blacks then too.)  Is it just down to equipment ? Certainly without the combination of lens, and shake reduction and modern cameras’ capabilities at high ISO meant I could shoot by available light – without them using flash would have given no chance to get something as natural as this.  What does the photographer contribute? Decide how they envisage the result, choose where to stand and pick what Henri Cartier-Bresson dubbed the decisive moment, if there is a learnable skill in picture making (as distinct from camera operation) , it is being ready for those moments when they present themselves.

tweetmeme_style = ‘compact’;
tweetmeme_url = ‘http://blogs.technet.com/jamesone/archive/2009/09/20/story-of-a-photo.aspx’;

This post originally appeared on my technet blog.

September 14, 2009

On PowerShell function design: vague can be good.

Filed under: How to,Powershell,Virtualization — jamesone111 @ 5:22 pm

There is a problem which comes up in several places in PowerShell – that is helping the user by being vague about parameter types. Consider these examples from my Hyper-V library for PowerShell

1. The user can specify a machine using a string which contains its name
Save-VM London-DC or Save-VM *DC, or  Save-VM London*,Paris*

2. The user can get virtual machine objects with one command and pipe these into another command
Get-vm –running | Stop-VM

3. The user can mix objects and strings
$MyVms = Get-vm –server wallace,Grommit | where { (Get-VMSettings $_).note –match “LAB1”}
start-vm –wait “London-DC”, $MyVMs

The last one searches servers “wallace” and “Grommit” for VMs, narrows the list to those used in lab1 and starts London-DC on the local server followed by the VMs in Lab1.

In a post I made a few days back about adding Edit to your profile I showed a couple of aspects of about piping objects that became easier in V2 of PowerShell,
Instead of writing Param($VM) , I  can now write

       [parameter(Mandatory = $true, ValueFromPipeline = $true)] 

Manatory=$true makes sure I have a parameter from somewhere, and ValueFromPipeLine is all I need to to get it from the the pipeline. PowerShell offers a ValueFromPipeLineByPropery option which looks at the piped object for a property which matches the parameter name or a declared [alias] for it. I could use that to reduce a VM object to its name, but doing so would lose the server information (which I need in example 3 above) and it gets in the way of piping strings into functions, so this is not the place to use it.
Allowing an array gives me problems when the array members expand to more than one VM (in the case of wildcards).  The code for my “Edit” function won’t cope with being handed an array of file objects or an array of arrays, but it doesn’t need to, because I wouldn’t work like that. But things I’m putting out for others need to work the way different users might expect, this needs to handle arrays in arrays (like “london-DC”,$myVMs ) arrays of VM objects ($myVMs), so time for my old friend recursion, and a function ike this.

Function Stop-VM
{ Param(
        [parameter(Mandatory = $true, ValueFromPipeline = $true)] 
        $Server = “.”
           if ($VM –is [String]) {$VM = GetVM –vm $vm –server $server}
           if ($VM –is [array])  {$VM | foreach-object {Start-VM –vm $_ –server $server}}
           if ($VM -is [System.Management.ManagementObject])  {
               $vm .RequestStateChange(3)


This says, if we got passed a single string (via the pipe or as a parameter), we get the matching VM(s), if any. If we were passed an array , or a string which resolved to an array, we call the function again with each member of that array. If we were passed a single WMI object or a string which resolved to a single WMI object then we do the work required.

There’s one thing wrong with this, and that is that it stops the VM without any  warning I covered this back here.  It is easy to support ShouldProcess; there is level at which Confirm prompts get turned on automatically, (controlled by $confirmPreference) and we can say that the impact is high – and at the default value the confirm prompt will appear even if the user doesn’t ask for it.

Function Stop-VM
{ [CmdletBinding(SupportsShouldProcess=$True, ConfirmImpact='High')]
          [parameter(Mandatory = $true, ValueFromPipeline = $true)] 
          $Server = “.”
           if ($VM –is [String])  {$VM = GetVM –vm $vm –server $server}
           if ($VM –is [array])  {$VM | foreach-object {Stop-VM –vm $_ –server $server}}
           if ($VM -is [System.Management.ManagementObject]
                   –and $pscmdlet.shouldProcess($vm.ElementName, “Power-Off VM without Saving”) {
               $vm .RequestStateChange(3)

Nearly there, but we have two problems still to solve: and a simplification to make the message. First the simplification; Mike Kolitz  (who’s going through the same bafflement as I did with Twitter, but more importantly has helped out on the Hyper-V library), introduced me to this trick : when a function calls another function using the same parameters – (or calls itself recursively) if there are many parameters it can be a pain.  But PowerShell has a “Splatting” operator. @$PsboundParameters puts the contents of a variable into the command.  (James Brundage, who I’ve mentioned before wrote it up) And you can manipulate $psboundParameters, so Mike had a clever generic way of recursively calling functions.

if ( $VM -is [Array])   { [Void]$PSBoundParameters.Remove("VM") ;  $VM | ForEach-object {Stop-VmState -VM $_ @PSBoundParameters}}

In other words remove the parameter that is being expanded, and re-call the function with the remaining parameters, specifying only the one being expanded. As James’ post shows it makes life a lot easier when you have a bunch of switches.
OK, now the problem(s) the message

Are you sure you want to perform this action?
Performing operation "Power-Off VM without Saving" on Target "London-DC".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): n

Will appear for every VM, even if we select Yes to all or No to all. Each time Stop-VM is called it gets a new instance of $psCMDLET And what if we don’t want the message – for example in a script which kills the VMs and rolls back to an earlier snapshot.  Jason Shirk, one of the active guys in our internal PowerShell alias pointed out first you can have a –force switch and secondly you don’t need to use the function’s OWN instance of psCMDLET – why not pass one instance around ? So the function morphed into this

Function Stop-VM

{ [CmdletBinding(SupportsShouldProcess=$True, ConfirmImpact='High']


          [parameter(Mandatory = $true, ValueFromPipeline = $true)]



          $Server = “.”,






          if ($psc -eq $null)  {$psc = $pscmdlet}

if (-not $PSBoundParameters.psc) {$PSBoundParameters.add("psc",$psc)}

          if ($VM –is [String])  {$VM = GetVM –vm $vm –server $server}

          if ($VM –is [array])  {$VM | foreach-object {Stop-VM –vm $_ –server $server}}

          if ($VM -is [System.Management.ManagementObject]

                 –and ($force –or $psc.shouldProcess($vm.ElementName, “Power-Off VM without Saving”)) {

              $vm .RequestStateChange(3)




So now $PSC either gets passed or it picks up $pscmdlet and then gets passed to anything else we call – in this case recursive calls to this function.  And –force is there to trump everything.  And that’s what I have implemented in dozens of places in my library.

This post originally appeared on my technet blog.

How to view RAW image files on Windows 7 (and Windows Vista).

Filed under: Photography,Windows Server,Windows Vista — jamesone111 @ 4:09 pm

My photography posts appear to be a bit like busses. I don’t make one for a while then two together …

Some while back I wrote a tale of two Codecs bemoaning the patchy support for RAW files.  Basically we (Microsoft) don’t provide codecs for anything other JPG, TIF, PNG and our Windows Media formats. Everything else is down to whoever is responsible for the format showing a bit of leadership. Pentax fell a bit short with the codec for their PEF format – no 64 bit support. Still, a 32 bit codec works in 32 bit apps –like live Windows Live Photo Gallery, and if one of those previews the image and creates the Thumbnail it then shows up in explorer. At least Pentax’s Codec will install: they support Adobe’s DNG format as an alternative and Adobe’s rather old beta codec won’t install on 64 bit Windows 7. I discovered Ardfry’s Codec for DNG, which is pretty good, though not free.

Putting QuickTime player onto my rebuilt PC I find that it has partial codec support for WIndows – i.e. some Mov files can be played in Windows Media Player and show a thumbnail in Explorer , and some can’t (it appears the “can” use H264 video and “the can’t” are CinePak or Sorenson). Before I had a chance to get the latest build from Ardfry, someone sent me a link to this page of Codecs from Axel Rietschin Software Developments.  I’ve only installed and tested the 64 bit ones PEF and DNG ones but the initial impression is very good indeed. The only gripe is that there doesn’t seem to be a way for the Codec to return the meta data information from the picture but tell Windows “For this format the meta data is read only” – with both Axel’s and Ardfry’s codecs you can enter new data only to get an error when Windows tries to save it.

The full list of supported formats is as follows.

Adobe Digital Negative (*.dng  )
Canon Raw Image  (*.cr2, *.crw )
Fuji Raw Image (*.raf)
Hasselblad Raw Image (*.3pr, *.fff)
Kodak Raw Image (*.dcr, *.kdc )
Leica Raw Image (*.raw, *.rwl)
Minolta Raw Image (*.mrw)
Nikon Raw Image (*.nef, *.nrw )
Olympus Raw Image (*.orf)
Panasonic Raw Image (*.rw2)
Pentax Raw Image (*.pef)
Sony Raw Image (*.arw, *.sr2, *.srf)

A nice bonus is that these were created to support Fast Image Viewer, which I hadn’t come across before: this supports tethered shooting on Cameras with PTP support (like my new Pentax K7). I’m going to give this a try and I’ll hand over the small pile of pennies required if it works. Update there are different levels of PTP support, and the K7 doesn’t do what I need it to. Sigh.

This post originally appeared on my technet blog.

Photosynth re-visited

Filed under: Uncategorized — jamesone111 @ 1:13 pm

One of the things that I’ve said many times is how great today’s technology seems. The first computer I worked on used punched paper tape. We would need 2 miles of tape to hold 1MB of data. Moving from film photography to digital has meant we can shoot far more pictures: Victorian plate photographers would coat, expose, and develop a tiny number of plates. The relative cheapness and ease of working with film, made photography more practical. Still: shooting hundreds of pictures in an afternoon was the province of the professional or very rich. That has all changed with digital, this morning with a couple of spare memory cards in my bag I had the equivalent storage to a strip of paper tape to go all the way round the planet. Battery capacity is the limiting factor on the number of pictures I can shoot, and since a battery lasts the thick end of 1000 shots it’s not much one.

Both my family and my in-laws live by the seaside, and while visiting early this year I shot about 530 pictures over a couple of days, with a view to putting them into photosynth. Unfortunately they sat forgotten on my hard disk until the recent upgrade  and  disk swap gave me a shove to have a bit of tidy-up of the tens of gigabytes of photos which account for most of disk space. In paper-tape terms the ones waiting to be go into this one synth would have used enough paper tape to go from here to Baghdad*. Time to do the synth. And I have to admit to a certain amount of satisfaction that of the 535 photos it was able to link 97% into a synth. In the year since it was launched there have been several updates to Photosynth. There is more to come, which I’m looking forward to, but I’ll leave it to those working on it to say what (and when). In the meantime, if you’re interested in photography and haven’t had a play with photosynth yet – well you should: you can start with my synths or just head for the home page.



* To a reasonable approximation there are 64K inches in a mile and 8 bytes per paper tape inch give ~ 2Miles per MB. My 1.3GB comes out about 2600 miles, and when I checked for a city 2600 miles from London…

This post originally appeared on my technet blog.

September 12, 2009

For your viewing pleasure …

Filed under: Blogcasts,Windows 7,Windows Server 2008-R2 — jamesone111 @ 9:51 pm

For the last few weeks, on and off, Andrew and I have been working on a set of Videos on Windows 7 and Server 2008-R2, which are now available  on youTube. When we were kicking ideas around we came up with the idea of filming Andrew drawing cartoons of what the Screencasts will cover. Like most good collaborations once we got the idea neither of us is terribly certain who thought of what, and when we just being a listening post for the other. Andrew understood we could have click through navigation long before I did, so you click on something he has drawn and go to one of the screen casts which shows the detail. I must admit I never thought I’d end up spending an afternoon filming the linking up of cartoons with coloured string to illustrate remote desktop and VDI, and the though is always “Is this a great idea, or a waste of time”. So far we’ve had some very pleasing comments and if people have got suggestions for more stuff please let me (or Andrew) know about them. Other feed back is always welcome too.

This post originally appeared on my technet blog.

How to use $myInvocation to do simple command profiling in PowerShell

Filed under: Uncategorized — jamesone111 @ 9:32 pm

One of the things I’ve noticed on our internal PowerShell DL is that some of the Redmond cognoscenti like to have the history ID in their PowerShell prompt and I was never sure how they did it. 
Then the other day I noticed it was part of the $MyInvocation automatic variable, so it is easy enough to add that to the prompt function – in case you didn’t know PowerShell calculates the prompt with a function, so all kinds of creativity can be deployed there.

Over the last day or so I have been playing with some stuff in PowerShell which takes a long time to run. My old university tutor would be glad that I worked out the algorithm I’m using will take Order n-cubed time to run. I can’t see an improvement to the overall way of solving the problem, but I can put some short cuts in. What I wanted to know was whether it would run any quicker. One neglected part of the History in PowerShell is that that gives you start and end execution time, so I ended up doing this

h    #Alias for get-History

note the last number for example 123,

$hh=h 123

Putting the history item in a variable lets me use [tab[ to expand the EndExecutionTime , Subtract and StartExecutionTime so it actually saves typing

Thinking about $MyInvocation.History, I realized I could automate this, and just added the following to my profile

function howLongWasthat {
  (get-history ($MyInvocation.HistoryId -1)).endexecutiontime.subtract((get-history ($MyInvocation.HistoryId -1)).startexecutiontime).totalseconds


So now after running a command I type how [tab] [enter] and hey presto it gives me the run time. 

Following on from my previous post , do you have any magic profile entries to share ?

This post originally appeared on my technet blog.

Select string. Finding a PowerShell *

Filed under: Uncategorized — jamesone111 @ 3:34 pm

I’ve thinking about odd figures of speech. Like telling one’s naughty children “I’ll swing for you one of these days”. Since no one has been hanged in Britain in my life time , it is anachronistic as well macabre.
I like “Using X is like trying to kick a dead whale across a beach with your bare feet” – although a quick search showed I’d been both misquoting and misattributing it for years, and I’m prone to using the Blackadder-eque phrases like “Doing Y is like looking for a black cat, in a coal cellar, at night, without a torch, when the cat isn’t there”. (Who has a coal cellar these days. It sent me scurrying back to  Clive James for a thought on what happens to old metaphors.) 

Phrases like these last two bubble up in mind when I find myself working with regular expressions. I suspect people in the Unix world tend to find themselves working with regular expressions more, because the tools (most famously grep) are there. We’ve had FIND from DOS all the way to today and, well, lets just call it a triumph of backward compatibility. This is another case where the landscape changes with PowerShell. I’ve been trying to finish a new release of my PowerShell library for hyper-V. I mentioned before that when I right utilities for others I try to allow the user to provide input to many commands in more than one way. So I’ve been testing the each command with different syntax variations, and letting PowerShell make a transcript of session. Is there and easy way to check I have run all the commands I need to test. Cue Select-String.

I meet people with Linux/Unix environments who have taken to PowerShell in a big way, and if you happen to be one of them let me recommend an investigation of select-string. It’s the most useful text processing tool I’ve found since I found about parsing text to columns in Excel (I had Excel 2.0 on my Windows 2.03 system 20 years ago, so this a long time).  With a transcript of my test session, I could do

Select-String -Pattern “^PS” -Path .\test-pass1.txt 

^PS isn’t to scary as regular expressions go , it says “At the start, PS” ,so this will get all the lines with a PowerShell prompt at the start If you just want to know the files that contain a match you can use the -match switch, but I want the details which come back as MatchInfo objects containing the path and short file name, line-number, line of text, the pattern that matched on a line and the what matched for that pattern.

Armed with the lines which contain commands, the next step was to find out which commands where in those lines. Something else I keep pointing out to people about PowerShell is the behaviour of allowing multiple items in a parameter where it makes sense. So for my pattern I could write “Get-VM”,”Get-VMDISK”,”Get-VMNIC” except that I have about 100 commands and could do without typing them in, so I saved myself the bother I wrote this instead:

$Patterns = (get-command -Module hyperv | % {$_.name })

Select-String -Pattern “^PS” -Path .\test-pass1.txt | select-object line | 
    Select-String -Pattern $patterns | select-object matches

This appeared to work, but it only got one match from each line: it turns out there is a -All switch, but worse Add-VM or Get-VM seemed to match instead of Get-VMDisk or Add-VMNIC, or whatever so I needed to check for a space character after the name – that’s \s in regular expression syntax. This still only produced one hit per line. It seems select string doesn’t test all the patterns if one matches, that’s it. It took a moment to work it out, I needed one giant pattern expression which said, this or this or this or this. You can do that with a | sign so I reworked what my patterns would be

$patterns=get-command -Module hyperv | ForEach-Object -begin   {$patterns=””} `
                                                        -process {$patterns += $_.name + “\s|”}` 
                                                        -end     {$patterns -replace “\|$”,””}

Or in English, Start with an empty string, build it up by adding the name and \s (space) | (“or”) , and find a trailing | sign (\| ‘escapes’ the character) and replace it with nothing and return the result.  (I’ve grown to like that trick of -replace “X$”,”” – for remove ‘X’ at the end of something , if there is one. –replace and –match in PowerShell use regular exmpressions).  And I got the right matches, with some grouping, sorting and formating I had what I wanted to know

Select-String -Pattern “^PS” -Path .\test-pass1.txt | select-object line |  Select-String -Pattern $patterns -all |


ForEach-Object {$_.matches } | group value | sort count | format-table -auto name, count

Name                     Count

—-                     —–
get-vmnic                    1
remove-vm                    1
set-vmnicvlan                2
export-vm                    3
Get-VMDiskController         3
Get-VMDriveByController      3
Add-VMSCSIController         4
new-vm                       4

get-vmdisk                   5
New-VMSnapshot               5
add-vmnic                    5
new-vhd                      5
Set-VMMemory                 6
set-vm                       6

Set-VMCPUCount               6
add-vmdisk                   8
Add-VMDrive                 11
get-vm                      21

Just for fun I got rid of the pattern variable and made it one line. There are 1028 lines in my transcript, and checking the command history I found it only took 0.34 of a second to do all of the work.

This post originally appeared on my technet blog.

September 10, 2009

Windows 7 upgrades: my experience

Filed under: Windows 7 — jamesone111 @ 3:38 pm

I’ve done more than my share of Windows upgrades. I’m fond of telling people that my first proper project in IT as a professional involved updating the software supplied on the company’s computers from Windows 1.03 to Windows 2. I didn’t run NT as my desktop OS until version 4, and never ran Windows 98 or ME, other wise I ran just about every release of DOS from 3.1 forwards, and Windows 1,2, 2.1 (/286 and /386) 3.0, 3.1, 3.1-for-workgroups and 3.11 for workgroups, NT 4, Windows 2000, XP, Vista and 7, including the betas of most of them. I’ve managed plenty of non-Microsoft stuff, and all my experience has taught me that in-place upgrades save you a few minutes only to cost you hours later. I understand that there are cases where people need to do an in place upgrade (the classic case being where a machine is supplied with bundled software, and a recovery image disk but no separate installation disks), but its best avoided.

My experience with upgrading to the release version of Windows 7 has been slightly convoluted, and is still the best I’ve had by some margin. Firstly I was running 7 on a spare hard disk. So I went back to my original disk for release. The over the network installation takes a couple of hours, but it needs seconds of my time. It went like this

  • Boot my computer press F12 to get to the one-time boot menu, select network and press F12 again to allow the boot to proceed.
  • From a menu which offers me automated data migration, server installation and so on, choose Windows 7 64  bit with Office 12/14
  • Choose my language settings, and enter my network credentials to get the installation image from the server. Go to a meeting.
  • Come back from the meeting, set-up has paused having installed Windows and various extras, it wants me to decided on released office or the new version. I just can’t have a PC with all released software on it. Office 2010 goes on, and I go to lunch
  • Come back from lunch , logon for the first time, let Windows update do its stuff (which brings a better screen driver in), run Windows Easy Transfer to copy my data back. Go to another meeting.
  • Go into outlook – while it is syncing , install the non-standard, apps which I use
  • Continue working as if nothing had happened.

Someone called me a curmudgeon recently, and the complaint I’m left with after putting Windows 7 on is there is no sense of achievement; no sense of having overcome something: when I used a USB stick to put it onto a netbook at home I was expecting to hunt down drivers and be able to point to something at the end and say “I did that”; it did it all by itself. The image at work just takes that to another level. Microsoft IT have a harder job than you might think – a commitment to running pre-release software in production and most employees think they know better. I can remember a time when the laptop images which Microsoft IT put a machine were so far from being useful the best thing you could was to round up a stack of CDs,wipe it and build it properly yourself. The new imaging technology which came in with vista means they provided a very small number of images and devote their time to getting those right. (Previously they had to maintain many images – and couldn’t spend enough time on any of them. Now the reverse is true – the standard image is now so good that the idea of getting the stuff together to do my own has no appeal whatsoever. One of the guys from Microsoft IT told me they got some great scores on their internal feedback survey about the pre-release of Windows 7, and this will form the basis of a story on IT showcase. It’s made them into heroes.

As it says in a Jonny Cash song “Well, up till now my plan went alright”…  I have just got a new 500GB disk for my secondary laptop – which runs as a hyper-v server and needs the space for a zillion VHD files: now it has the space this machine will dual boot into Server 2008, or a VHD based Server 2008-R2 image. Until this week it has been on 2008 only. The process was to do an image backup of Windows 2008 to plug in an external drive and do a Windows image backup; change hard-disks, boot off the Windows 2008 setup disk and do a full image restore. The process ran like clockwork , but at the end I had a 160GB disk which was going to gather dust and 100GB disk in my laptop. Why hadn’t I done this upgrade first ? Time to swap drives… So  I went to  Windows 7 backup and made an image of the machine I’d just built. At the end of this, the backup process offered to make a recovery disk , and I took that option. I swapped the drive, booted from my new recovery disk and a couple of clicks and a cup of coffee later the machine was waiting for me to logon as if nothing had happened. At least here my 20 years experience upgrading systems paid off – I had to extend the disk partition after the restore. But even that has got so much easier since the days of risky 3rd party tools which would extend a partition.

This post originally appeared on my technet blog.

September 2, 2009

How to load files into the PowerShell ISE editor – or “What’s in your profile”

Filed under: Uncategorized — jamesone111 @ 7:39 pm

(another in the “Things you’ll want to do with PowerShell V2” series)

One of the tricks I have been meaning to post for a little while is a neat way to edit a file in the new PowerShell Integrated Scripting environment. If you are working in the “traditional” shell you just type “notepad filename” and you’re editing the file but what how can you have a command line to load up a file in the ISE ? It turns out to be quite easy. $psise.CurrentPowerShellTab.Files.add(C:\myStuff\MyFile.ps1)

The ISE has an object model and there is an automatic variable which points to the root of it, so all you have to do call one of its objects, give i the full path of the file to load and hey presto. But it doesn’t exactly trip off the fingers.

So here was the first go.

function edit
{ param ( $Path )
    $null = $psise.CurrentPowerShellTab.Files.add($_.path)

Easy enough, but PowerShell can do much better than that. For starters it can resolve the path for us, and if it resolves to multiple files (for example *.ps1) then we’ll get all of them.

function edit
{ param ( $Path )
             Resolve-path $path | foreach-Object { $null = $psise.CurrentPowerShellTab.Files.add($_.path)}

My first instinct was to hand Resolve-path one item at a time, but it is quite happy being passed multiple paths like *ps1,*.PsXML so this version of the function will version open multiple wildcards. This was starting to look like I would want to be able to pipe things into it. And By now I was realizing that I would want to use it in the traditional shell as well. So I made three final modifications . The first one says I can pass it objects which have a Path, FileName or FullName property and that property will get treated as the path. The Second is because a function can have a begin, process and end block, this should go in the process block to be called for each object piped in, and the last says if the the name of the PowerShell host isn’t the ISE then launch the file in notepad.

function edit
{ param ([parameter(ValueFromPipelineByPropertyName=$true)][Alias("FullName","FileName")]$Path )
    process {
             Resolve-path $path | foreach-Object { $_
                if ($host.name -match "\sISE\s") {$null = $psise.CurrentPowerShellTab.Files.add($_.path)}
                else                             {notepad.exe $_.path}

I had the first version working for a few days before I changed it to allow the value from pipe line by property name after reading something on our internal PowerShell alias (I’d swear it came from James Brundage but I can’t find it). It means I don’t have to test for different kinds of objects being piped into the command – I can just anticipate the property names. This came into its own last night when I found I had the same error in about 20 different PS1 files. It was easy enough to find them all and open them with one command.

select-string -Pattern "ParameterSet" -path *.ps1 | edit

The updated version is now in my profile – and since moving up to version 2, my profile has become one which works for both ISE and Traditional PowerShell – there are actually 6 profiles, current user, and all user and all hosts/”current host”  – which is either the Shell or ISE host. The table below maps them out – but you can find them as properties of $profile.

$profile.CurrentuserCurrenthost $env:userProfile\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1
$profile.CurrentuserAllhosts $env:userProfile\Documents\WindowsPowerShell\profile.ps1
$profile.AllusersCurrentHost $env:windir\System32\WindowsPowerShell\v1.0\Microsoft.PowerShellISE_profile.ps1
$profile.AllusersAllHosts $env:windir\System32\WindowsPowerShell\v1.0\profile.ps1

Bonus Looking for the information about profiles I found this post of Jeffrey’s on adding custom commands to the menus in the ISE. The syntax has changed but it showed me how I could do

$psise.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Bulk edit", {Edit (Read-host "Enter file(s)") }, 'Ctrl+E')

and have bulk edit on a hot key / menu item…

This post originally appeared on my technet blog.

Create a free website or blog at WordPress.com.