PowerShell & BlackBerry Web Services (Part 2 – Loading)

In my previous post (here), I ran through the process of downloading and creating your own C# file and then compiling that into a DLL for use with BlackBerry’s Web Services (version 5.0.3+).

After that work, you now have yourself a BesProxy.cs and a BesProxy.dll file that you can use to create the objects for use with BlackBerry Web Services.

Note: Inherent to the .NET Framework, there is no way to “unload” a class once it’s been registered. To exit out of it, you’ll need to close the PowerShell session and reload it. Please keep this in mind as you are working with your coding/scripting.

There are two ways to load these types into PowerShell. Both use the Add-Type function, but the parameters are different.

The first is using the C# file as the source and it looks like this:

$BesProxy =  Add-Type -Path "C:ScriptsBlackBerryBesProxy.cs" -ReferencedAssemblies "System.ComponentModel",
System.Web.Services","System.Xml","System.Xml.Serialization" -PassThru

This loading will work, and it doesn’t have any problems. The only benefit that I see in using this is if you wanted to dynamically alter the Web Services URL in the C# file prior to loading.

Since I don’t really care about that too much, I decided to go with the simpler load which is this:

$BesProxy = Add-Type -Path C:ScriptsBlackBerryBesProxy.dll -PassThru

You can see that this one uses the DLL as the source and thereby already includes the necessary assemblies.

If you have ever used the Add-Type function before, you’ll note that you don’t need to assign it to a variable. The reason I did was so that I could enumerate the members easier. If you want to do it my way, be sure to include the –PassThru parameter at the end, otherwise no object is generated when the types are loaded into the system.

Now if I want to verify that the types have been loaded, I can just ask for the members of the BesProxy variable.

$BesProxy | Format-Table Name, Namespace

So, now PowerShell is aware of our types and the class definition. Where do we go from here? Part 3 examines the sample code provided by Research In Motion in detail and how we’ll handle working this in PowerShell.

6 thoughts on “PowerShell & BlackBerry Web Services (Part 2 – Loading)”

  1. Thanks mate, this one works like a charm for BES 10.1 awesome tutorial. Now i got a hang of it and created my own functions to CreateUser,AssignToGroup and assignEmailProfiles.
    Regards
    Dan

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.