다음을 통해 공유


How to do PowerShell on your phone

Even Spiderman would envy this web action. Today we're going to walk through setting up a portable PowerShell v3 Web Access demo. Using this demo guide you can explore PowerShell from any web-capable device: your phone, your tablet, or your Raspberry Pi.  The links in this post will guide you to all of the key documentation to build your own PowerShell Web Access lab.

GoateePFE-PowerShell-Phone-Surface-Laptop-VM-Edit

Thanks to my buddy Bruce Adamczak for the picture above. Bruce snapped it while I was doing this demo for a customer in the field.

A couple weeks ago I was flying home from helping a customer get their Active directory healthy, and it dawned on me that I had everything I needed for a wow-factor PowerShell demo right there in my backpack. When I landed in Atlanta I put this demo together between flights. I was grinning ear-to-ear with my laptop, Surface, and Windows Phone sprawled out on one of those tiny airport waiting area seats. I know people thought I looked goofy… dude with a goatee grinning at his laptop and tablet and phone all at once.

One of my favorite Iron Man quotes is from the first movie when Obadiah Stane says, "Tony Stark was able to build this in a cave… with a box of scraps!" In other words, this demo will only take a few pieces to get rolling.  And I’m not Tony Stark.

The Plan

The demo consists of a domain controller VM and an IIS VM running on my laptop, both on an internal network. The IIS VM has another virtual network connection configured for the external network with a static IP at the upper end of the same IP range issued from DHCP on the WiFi access point. My phone and tablet are getting DHCP from the same WiFi access point. Technically we could put the DC on the same external network, but using a separate internal network would be more like reality where the web server has a reverse proxy to access internal resources.  Here is a crude illustration:  (Hey, I’m an engineer, not an artist.)

clip_image001

The Parts

Here is all you need to get this going:

  • A wireless access point - I used my Verizon MiFi.
  • A laptop running Windows 8 Client HyperV.
  • A wifi tablet with a browser - I used my new Microsoft Surface RT.
  • A wifi smartphone with a browser - I used my Verizon HTC 8X Windows Phone 8.

Wireless

Any WiFi access point or router should do. Configure DHCP so that you have at least one extra address above the range.  This extra address will be statically assigned to your IIS server external virtual NIC.  I used the address 192.168.1.200.

Client HyperV

You’ll need a 64 bit install of Windows 8.  Most newer laptops have SLAT (second layer address translation) built in to support Client HyperV. Install HyperV from Windows Features.  Use this post for setup instructions.

Technically you would only need one VM for this demo: a Windows Server 2012 install running Directory Services and IIS. Obviously that would never be recommended in a production environment.  I have four VMs for more demo flexibility:

  • Windows Server 2012 Domain Controller
  • Windows Server 2012 Member Server
  • Windows Server 2012 IIS Server
  • Windows 8 client

You can download evaluation installs here for your own free testing:

All of the VMs are joined to the test domain on the DC.

Screenshot (12)

Networking

This is the tricky part. I'm not a HyperV expert, but I know enough to configure internal and external networks using the virtual switch (after I read the help). VMs on the internal network use the static addresses pictured in my crude illustration above.  Then I can use Remote Desktop Connection Manager to RDP into each virtual server from the host laptop where I have a static IP configured on the internal bridge NIC.  The RDP part is optional but convenient.  Most folks will use the HyperV virtual machine connection to interact with the VMs.

On the web server VM I configured two NICs: one internal and one external.  Inside the VM the internal NIC has the static 10.x.x.x address and the external NIC has the static 192.168.1.200 address.

image

Web Server

Once you have built your IIS VM you can use this article from the PowerShell team to step through the PowerShell Web Access setup. I was surprised that this only took five minutes in my lab. They did a good job building the setup cmdlets to automate all of the IIS configuration. Call the site "pswa".  Here is another link for more setup options.  If you want the full textbook documentation it is on TechNet here.

Web Clients

Now create a favorite or shortcut from Internet Explorer on the Windows 8 client VM, on the tablet browser, and on the phone browser. The URL should look something like this: https://192.168.1.200/pswa .  Any browser that supports HTTPS, JavaScript, and cookies should work.

PS – I tried this on my XBOX with the new IE app.  However, it did not appear to work.  From what I understand the XBOX browser does not support JavaScript.  I could be wrong.  Let me know if you get this to work.

Bringing It All Together

Once you’ve walked through these links and ironed out the kinks you should have a working PowerShell Web Access lab.  When you hit the URL you’ll get a page that looks like this.  Note that I have filled in the credentials and target computer name.

image

By the way, you will likely get a security prompt in the browser that the web site’s certificate is invalid. You can safely ignore that, because we’re just using a test certificate in the lab. For Windows clients you may need to launch the browser as Administrator to bypass that warning.

After clicking the Sign In button you’ll get the PowerShell console.  As they say in the movies, “I’m in!”

image

See this article for all of the tips on using the PowerShell Web Access console.  You’ve got to try this from your phone.  For example, most phone touch keyboards do not have a TAB key for doing TAB completion in the PowerShell console.  That’s why we put the little TAB icon on the toolbar at the bottom.  We also added up/down arrows for cycling through the command history.

A PFE peer of mine, Rick Sheikh, wrote a very thorough post recently on PowerShell Web Access.  I would encourage you to read it for all of the possible configuration and security options you can tweak.

Bring The Wow

Now what?  We’re in.  Any way to add some “wow” to this demo?  You bet.

Go watch this TechEd session with Travis and Hemant.  Fast forward to the 52 minute mark where they discuss disconnected sessions and then transition to PowerShell Web Access.  I posted a copy of these demo scripts when I spoke at TechMentor last autumn.  (Thanks, Travis and Hemant!)  Download the scripts, watch the video demo, and see if you can recreate the part at the end where they “pull a rabbit out of the hat” in the web session.  That’s the wow, especially when you do it from your phone.  I saved the commands into a demo.ps1 script to run from the phone instead of typing it all during a live demo.

Presentation Setup

When I do this demo for an audience here are the steps I take to utilize the lab:

  1. Boot up the Verizon MiFi and connect the devices.  I have already added the wireless network to my phone and Surface so that they connect right away.
  2. Boot up the VMs on my laptop.
  3. Create a shortcut on the phone and tablet pointing to the PowerShell Web Access page hosted on my laptop VM.  Test the page from each device to make sure it is working.
  4. Connect my laptop to the projector.  Plug in the Surface VGA dongle so that it is ready.
  5. Enable Presenter mode on the laptop and the Surface.  (Windows + X, Mobility Center, Presentation Settings)
  6. Do the PowerShell Web Access talk from the laptop.  Use the scripts linked above for the demos.  Start the disconnected job with the counting demo.
  7. Switch over to the Windows 8 client VM and demo PowerShell Web Access from a normal desktop browser but don’t pull the results from the disconnected session yet.  Discuss convenience at work or at home.
  8. Disconnect the VGA cable from the laptop and plug it into the Surface VGA dongle.
  9. Launch the PowerShell Web Access shortcut from the tablet.  Log in.  Demo a couple commands from the web console but don’t pull the results from the disconnected session yet.  Discuss how cool this would be from the recliner at home.
  10. Switch over to the Camera app on the Surface.  Now the camera is live on the big screen.  Tell the people in the front row to wave.
  11. Position the phone in front of the tablet camera so the audience can see it.  Launch the shortcut for PowerShell Web Access on the phone.  Turn it to landscape mode.  Log in.  Discuss how handy this is if you have to fix something at work while at a soccer game with the kids.
  12. Demo PowerShell from the web console on the phone.  Do a “dir” to show the demo.ps1 file you pre-staged earlier in the Administrator profile folder on the server.  Then type “Get-Content .\demo.ps1” to show what the script will do.  You can use TAB complete with Get-Content for added effect.
  13. Now run the demo.ps1 file with the two lines to reconnect the session and display the running output from the disconnected session.  Wow!

Imagine The Possibilities

As you might guess the setup will require some time on your part.  It is not really that difficult, but there are a lot of steps.  The fun part is all the learning along the way.  And when you’re done it is quite impressive.  Sometimes I run the lab on my home network so that I can use my Windows Phone or Surface to play with PowerShell from anywhere in the house.  Yip.  I’m a geek.  And I bet you are, too, if you’re still reading at this point.

Now that you have a super-cool PowerShell Web Access lab what can you do with it?  With over 2,400 cmdlets to explore and PowerShell under the covers of all the Windows server products the sky is the limit.  Imagine the possibilities for remote administration now across all products and technologies with PowerShell from your phone or tablet.

Typing on the phone keyboard may be tedious, but when you’re offline at a family event it is much easier than driving into the office to take care of business.  And that is why we created PowerShell Web Access.  Time for some PowerShell web slinging.  Enjoy!

Comments

  • Anonymous
    April 08, 2013
    Is 2008 or 2012 domain or forest level on the domain required for this to work?

  • Anonymous
    April 09, 2013
    The comment has been removed

  • Anonymous
    April 10, 2013
    Thanks for the confirmation. What I was getting was an error when running Install-PswaWebApplication. It was stating that no webconfiguration could be found. Once I ran import-module webadministration  the PSWA install finished successfully.

  • Anonymous
    April 30, 2013
    See this TechNet Edge video for a great demo of PowerShell web access across different non-Microsoft devices. channel9.msdn.com/.../Edge-Show-21-MCSE-Reinvented-and-Windows-Powershell-Web-Access

  • Anonymous
    June 01, 2013
    This is awesome!

  • Anonymous
    March 18, 2015
    In this previous blog post we looked briefly at Windows PowerShell and remoting. Back then, we used a

  • Anonymous
    March 18, 2015
    In this previous blog post we looked briefly at Windows PowerShell and remoting. Back then, we used a

  • Anonymous
    January 22, 2016
    Hey Ashley. I know this has been out for a while but I wanted to say "good job". Very informative and easy to read. I'll be trying this out in the next day or 2.
    Thanks very much.
    Regards,.
    John

  • Anonymous
    September 26, 2016
    The comment has been removed