Archive for the 'MobileShell' Category

My First MobileShell Client

In-browser PowerShell command-line is not the only way to take advantage of the PowerShell-running web server.

With the help of the PowerGUI MobileShell SDK, you can build your own MobileShell clients and use all the same web services MobileShell is using for a totally different user experience. For example, you could build your own native iPhone, Android, Blackberry, or Windows Mobile clients, Silverlight PowerShell applications and so on.

Here’s a quick step-by-step tutorial to get started with the SDK. For simplicity sake I will be using Visual Studio 2010 (Release Candidate) and build a console application. It should be quite easy for you to do the same in your favorite development environment of choice. ūüôā

So let’s get started. Open Visual Studio, and create a New Project / Console Application (Visual C#) – I will call mine MyMobileShellConsole:

Then, on the Project menu, click Add Service Reference. For simplicity sake, click the Advanced button on that dialog box, and then click the Add Web Reference button at the bottom of the Advanced options screen.

In the Url edit box, provide the URL of the web services endpoint for your MobileShell installation: e.g. http://my-server-name/MobileShell/MobileShell/MobileShellWebService.asmx or https://my-server-name/MobileShell/MobileShell/MobileShellWebService.asmx (mind http or https). You will then be prompted for credentials of the account which has access to the server.

Also, change the Web reference name to something more meaningful – e.g. MobileShell.

Now we can open the Program.cs file (obviously, if you are not writing a console application) you will have something else.

Add a ‘using’ clause to include the MobileShell namespace:

using MyMobileShellConsole.MobileShell;

And run our ‘Hello World’ script in the main function:

// Connect to MobileShell web service endpoint
MobileShellWebService webService = new MobileShellWebService();
webService.CookieContainer = new System.Net.CookieContainer();
webService.Url = 
  "http://MyServer/MobileShell/MobileShell/MobileShellWebService.asmx";
webService.Credentials =
  new System.Net.NetworkCredential("MyAccount", "MyPassword");

 

// Execute our first script
ScriptState state = webService.ExecuteScript("'Hello World'");
System.Threading.Thread.Sleep(1000);

// Retrieve results
state = webService.GetCurrentScriptState();
Console.WriteLine((state.Command as WriteCommand).Text);

 

Console.ReadLine();

Your project will probably look like this:

That is it. You can now run the application, have your ‘Hello World’ script executed at the MobileShell server and get the results back.

As a Step 2, let’s have a slightly more advanced script, which would actually prompt user for the command, keep retrieving results while they arrive, and so on – this is quite easy to do as well:


// Connect to MobileShell web service endpoint
MobileShellWebService webService = new MobileShellWebService();
webService.CookieContainer = new System.Net.CookieContainer();
webService.Url =
  "http://myserever/MobileShell/MobileShell/MobileShellWebService.asmx";
webService.Credentials =
  new System.Net.NetworkCredential("MyUsername", "MyPassword");

// Prompt user for command
Console.WriteLine("Type PowerShell command to execute: ");
String strScript = Console.ReadLine();

// Execute it
ScriptState state = webService.ExecuteScript(strScript);

// Keep retrieving results until execution is completed
while (state.State != PipelineState.Completed)
{
    System.Threading.Thread.Sleep(100);
    state = webService.GetCurrentScriptState();
    if (state.Command != null) {
    Console.WriteLine((state.Command as WriteCommand).Text);
    }
}

webService.TerminateCurrentScript();
state = webService.GetCurrentScriptState();
Console.WriteLine((state.Command as WriteCommand).Text);

Console.ReadLine();

With this one, you can get a bit more fancy:

And there’s more! You can use web services to retrieve intellisense information, manipulate favorites, format output, and so on. See more examples here and build your own MobileShell clients and any PowerShell applications which you need running on PowerShell-less devices!

Advertisement

MobileShell and PowerGUI Pro podcast published

PowerScripting podcast episode in which Hal and Jonathan met with Darin Pendegraft, Kirk Munro and myself and discussed the latest news from the PowerGUI team just got posted here.

There were a lot of great questions ranging from the way our team works, origins of the project, differences between free and commercial versions of PowerGUI, extensibility APIs, and even future roadmap.

Check out the podcast recording here.

PowerGUI MobileShell Team on PowerScripting Podcast

Tonight at 9:30 pm EST Darin Pendergraft, Kirk Munro and myself will be there on Hal’s and Jonathan’s PowerScripting Podcast.

If you are not asleep at that time, please join the live video stream and ask any questions, share thoughts and so on. Also, this is the 100th episode of the show – so plenty of cool stuff to be shared!

See you in a few hours!

Running MobileShell on Windows 7

While only server versions of Windows (2003, 2008, 2008 R2) are officially supported as PowerGUI Pro MobileShell hosts in production use, if you just want to give it a quick try your Windows 7 laptop is perfectly fine. Here’s what you need to do:

1. Open the Windows Features dialog box,

2. Turn on Internet Information Services,

3. Then browse into World Wide Web Services / Security and select Basic Authentication:

4. Click OK to close the dialog box.

5. Start MobileShell setup.

6. On the feature selection step provide the license (license file available from here).

7. When you click Next, read the warning telling you that running the web site on Windows 7 is a bad idea and click Yes. ūüôā

8. Follow the setup for other settings (they are pretty straight-forward).

9. If you are sure to not ever use this site for real administration you can even select to use HTTP (instead of HTTPS) binding – this saves you from providing site certificate, but obviously is a bad idea for production because your traffic will go unencrypted.

10. When you click Finish you will get the browser launched for the newly installed MobileShell site and can start having some serious PowerShell fun:

Hope this helps you check out MobileShell and get excited enough to later spend time on real server deployment. ūüôā

MobileShell Demo

Here’s a quick recorded walkthrough of our in-browser PowerShell prompt in case you want to have a look at it before you install it yourself:

Once you watch it and get excited, give it a try! Download PowerGUI MobileShell beta, install it on a Windows Server and let us know what you think!

MobileShell SDK

Developers, here’s your chance to create exciting applications on top of PowerGUI MobileShell server backend! That’s right: everything you see in MobileShell including settings dialog boxes and intellisense is exposed as web services. Your application will be able to execute any PowerShell scripts in production environment over HTTP/HTTPS, preserve session state and even get meta information such as intellisense.

Which means that if you don’t like our in-browser implementation and want to develop a native iPhone/Blackberry/Symbian/Android/Windows Mobile client – you can quite easily do that (and probably even make some money out of the respective app stores ;))

Below is a sample in C# that uses the PowerGUI MobileShell API to:

  • Create, list, join and close sessions
  • Work with IntelliSense autocompletion lists
  • Manage favorite scripts

Hopefully it is straightforward enough to figure out how to perform similar calls in your development platform of choice.

For this particular example to work in Visual Studio, you need to add the MobileShell Web service as a Web reference to the .NET project you are working with. The URL of the service looks like: https://<MobileShell_server_name>/MobileShell/MobileShell/MobileShellWebService.asmx.

For details about adding Web references to Visual Studio, see http://msdn.microsoft.com/en-us/library/d9w023sx.aspx.

If you are using tools other than Visual Studio to run .NET code against the MobileShell Web service, you need to generate a Web service proxy using the wsdl.exe utility, which is distributed with .NET Framework 3.5. For details, refer to the help screen for the utility.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MobileShellExamples
{
 class Program
 {
  static void Main(string[] args)
  {
    ScriptExecutionExample();
    FavoritesExample();
    IntelliSenseExample();
    SessionsExample();
  }

  static void ScriptExecutionExample()
  {
   MobileShellWebService webService = GetWebServiceInstance();
   webService.CreateSession();

   string strScript = "while ( $true ) { $i++; \"Hello $i\"; sleep -m 300 }";
   ScriptState state = webService.ExecuteScript(strScript);

   System.Threading.Thread.Sleep(5000);

   webService.TerminateCurrentScript();

   state = webService.GetCurrentScriptState();
   Console.WriteLine((state.Command as WriteCommand).Text);
  }

  static void SessionsExample()
  {
   // Create the first session
   MobileShellWebService webService1 = GetWebServiceInstance();
   webService1.CreateSession();

   // Create the second session
   MobileShellWebService webService2 = GetWebServiceInstance();
   webService2.CreateSession();

   // Get a list of active sessions
   MobileShellWebService webService3 = GetWebServiceInstance();
   SessionDetails[] arrSessionIDs = webService3.GetSessions();

   // Close all sessions except the first
   for (int i = 1; i < arrSessionIDs.Length; i++)
   {
    webService3.CloseSession(arrSessionIDs[i].SessionID);
   }
   // Join the first session
   webService3.JoinSession(arrSessionIDs[0].SessionID);
  }

  static void IntelliSenseExample()
  {
   MobileShellWebService webService = GetWebServiceInstance();

   // Get autocompletion list for the "Get-" string (e. g. get all Get-* cmdlets)
   string strScript = "Get-";
   foreach (IntelliSenseItem item in
           webService.GetIntelliSenseCompletionList(strScript, strScript.Length-1))
   {
    Console.WriteLine(item.AutoCompleteEnding);
   }
   Console.WriteLine("");

   // Get autocompletion list for "Get-Help -" string.
   // (e.g. get all Get-Help cmdlet parameters)
   strScript = "Get-Help -";
   foreach (IntelliSenseItem item in
           webService.GetIntelliSenseCompletionList(strScript,strScript.Length-1))
   {
    Console.WriteLine(item.AutoCompleteEnding);
   }
  }

 static void FavoritesExample()
 {
   MobileShellWebService webService = GetWebServiceInstance();
   // List current favorites
   Console.WriteLine("### Initial list");
   foreach (FavoriteScript cmdFavorite in webService.GetFavoriteScripts())
   {
     Console.WriteLine("Name: " + cmdFavorite.Name);
     Console.WriteLine("Script: " + cmdFavorite.Script);
     Console.WriteLine("");
   }

   // Add a new favorite script named "Hello World"
   webService.AddFavoriteScript("Hello World", "\"Hello World!\"");

   // List current favorites
   Console.WriteLine("### New favorite script added");
   foreach (FavoriteScript cmdFavorite in webService.GetFavoriteScripts())
   {
    Console.WriteLine("Name: " + cmdFavorite.Name);
    Console.WriteLine("Script: " + cmdFavorite.Script);
    Console.WriteLine("");
   }

   // Find the favorite script named "Hello World"
   FavoriteScript cmdNewScript = webService.GetFavoriteScripts().First(
                                     fav => fav.Name == "Hello World");

   // Modify the script name and content
   webService.EditFavoriteScript(cmdNewScript.Name,
                                 "Time keeper", cmdNewScript.Script);

   // List current favorites
   Console.WriteLine("### Favorite script modified");
   foreach (FavoriteScript cmdFavorite in webService.GetFavoriteScripts())
   {
    Console.WriteLine("Name: " + cmdFavorite.Name);
    Console.WriteLine("Script: " + cmdFavorite.Script);
    Console.WriteLine("");
   }
  }

  static MobileShellWebService GetWebServiceInstance()
  {
   return GetWebServiceInstance(
       "http://myserver/MobileShell/MobileShell/MobileShellWebService.asmx",
       "mydomain\\administrator", "=1qwerty");
  }

  static MobileShellWebService GetWebServiceInstance(string strUrl,
                                         string strUser, string strPassword)
  {
   MobileShellWebService webService = new MobileShellWebService();
   webService.CookieContainer = new System.Net.CookieContainer();
   webService.Url = strUrl;
   webService.Credentials = new System.Net.NetworkCredential(strUser, strPassword);
   return webService;
  }
 }
}

Detailed SDK documentation (all methods and classes) can be found in the “PowerGUI Pro MobileShell 2.0 SDK” document posted here.

Give a try and let us know what you think. And obviously whichever apps you create we will be extremely glad to promote them whichever way we can!

Intellisense in MobileShell

The only thing better than PowerShell in a browser is PowerShell with intellisense (nice popup list suggesting cmdlets, options, operators and so on as you type). And MobileShell has it.

We provide it both in regular desktop browsers:

And on mobile devices – for example here’s how it looks on iPhone:

This makes your anywhere administration experience even more enjoyable!

Download PowerGUI MobileShell beta, install it on a Windows Server and let us know what you think!

MobileShell – PowerShell Prompt in a Browser

You can now manage your IT from any computer or mobile device which has a browser.

We have just started a public beta of the first component of the future PowerGUI Pro edition – MobileShell. It is effectively an web application you install on an IIS server. Once you installed the application, set permissions, and deployed the PowerShell snapins and modules you need – you just hit the URL from any browser, log in with your Active Directory credentials and get full PowerShell prompt you can use to manage your systems!

Communications are encrypted over HTTPS (you will obviously need a certificate for that), and the PowerShell code is executed under the account you are using to connect to the server – so all standard security applies.

And you can even connect to site from your smartphone such as Blackberry or iPhone:

Now next time you get an emergency call – there is no need to rush to your workstation. All you need to do is fire up a browser on your mobile device or a computer nearby – and you can fix the issue and keep enjoying your lunch, family time, or vacation. ūüėČ

We are extremely excited with this 3rd PowerGUI product (in addition to the admin console and script editor/debugger) and think it will make lives of thousands of IT professionals out there much easier!

Get the MobileShell setup and documentation here and please let us know what you think!


My Recent Tweets

Legal

The posts on this blog are provided ‚Äúas is‚ÄĚ with no warranties and confer no rights. The opinions expressed on this site are mine and mine alone, and do not necessarily represent those of my employer - WSO2 or anyone else for that matter. All trademarks acknowledged.

© 2007-2014 Dmitry Sotnikov

December 2022
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  

%d bloggers like this: