Device Emulator and the Windows PowerShell

Was playing around with Windows PowerShell recently and it ROCKS. there has been a lot of coverage around PowerShell so I won’t bore you with some of them, here’s a great video screencast by Scott Hanselman to get your started on PowerShell.

What I wanted to do was to see how easily it would be for one to write a test harness for automating the instantiation of Device Emulators so that developers and testers can quickly test their application on different device configurations.

This sample uses the Managed Core Connectivity Wrappers that we’ve built into Visual Studio 2008 and the new Windows Mobile SDK.

You need the following installed before you can proceed:

  1. Windows Mobile 5.0 or 6 SDKs

  2. Windows PowerShell 1.0

  3. PowerTab Version 0.98

Here’s how you can instantiate a device emulator from powershell.

Step 1: Start PowerShell in Administrator mode and enable script execution by typing “Set-ExecutionPolicy unrestricted”, especially if you’re on Vista.


Step 2: Load the Microsoft.SmartDevice.Connectivity assembly using the LoadWithPartialName method.


Step 3: Create the DataStoreManager object. “1033” is locale for “en-en”


Step 4: Query the types of platforms that are installed on your machine. This will return the list of Windows Mobile Emulator platforms that were installed together with the SDK. If you have not installed the Windows Mobile 6 SDK, you won’t see the Windows Mobile 6 Professional nor the Standard SDKs.


Step 5: Enumerate Platforms and create a collection of platforms in $plat. Assign platform that you’re interested in to $wm6, in this case we’re using the Windows Mobile 6 Professional SDK. (item 0 in the collection)


Step 6: Get the list of devices for that platform. This shows you all the possible device configurations / types that were installed with that platform.


Step 7: Let’s pick the Windows Mobile 6 Professional Emulator by picking device [1] and connect to the emulator using the $device.Connect() method.


That’s it 🙂 pretty powerful. You can imagine how flexible PowerShell is by allowing you to write .NET Code together with Shell code to create automated scripts. You can now easily instantiate emulators and deploy custom configurations automatically to create a full automated test environment.

Comments (7)

  1. Daniel Moth says:

    PowerShell combined with CoreCon

  2. Staffan Gustafsson says:

    Is it really necessary with an unrestricted execution policy? Wouldn’t RemoteSigned have worked?


  3. Loke Uei says:

    Staffan, of course not, that would be best way to do it, but i’m using unrestricted in this demo to make life easier for me. 🙂

  4. This looks great! So, do I need to have Visual Studio 2008 installed for the Managed Core Connectivity Wrappers or is the Windows Mobile 5 or 6 SDK enough?

    Having to install VS 2008 on my build server doesn’t seem like a good idea.



  5. Loke Uei says:


    yes unfortunately you need to have Visual Studio 2008 installed to get the CoreCon wrapper.

    Maybe you can install it, identify which components you need and copy them out manually 😉

  6. Thanks to those of you that attended Reed and my presentation at the Windows Mobile Partner Summit .