PowerShell script to open RDP session with an Azure VM

My Teammate Jeremy Foster recently shared some azure goodness that he added into his PowerShell Profile.  Then today, I ran across Brian Farnhill’s “Opening RDP session to an Azure VM with PowerShell” blog post and was inspired to add a simple function to my own PowerShell profile to simplify making RDP connections with my Azure VMs. 

From a PowerShell command prompt, I opened my profile in notepad (or the text editor of your choice)

notepad $profile

Then, to the bottom of my profile I added the following function

function rdpvm ($ServiceName,$Name) {
  $vm = (Get-AzureVM -ServiceName $Name -Name $Name)
  if($vm -and $vm.InstanceStatus -eq 'RoleReady') {
    $rdp = (Get-AzureEndpoint -VM $vm | where { $_.LocalPort -eq 3389})
    $fqdn = (New-Object System.URI $vm.DNSName).Authority
    $port = $rdp.Port
    Write-Host "Opening Remote Desktop Session with $($fqdn):$($port)..."
    Start-Process "mstsc" -ArgumentList "/V:$($fqdn):$($port)"
  }
  else {
    Write-Warning "The VM $($vm.Name) is not running ($($vm.InstanceStatus)).  You should start it first"
  }
}

Now, in the future, when I am working with Azure in PowerShell I can simply run the following to open an RDP session with a VM.  Of course, this assumes I’ve already used “Add-AzureAccount” to sign into my azure subscriptions. 

rdpvm -ServiceName <MyCloudServiceName> -Name <MyVMName>

Enabling Remote PowerShell Access for Secondary Administrators

If you want to use PowerShell Remoting to run scripts on a remote computer using an account other than the target machine’s built-in administrator account, you will  need to do a couple of things:

  1. On the target machine, create another user account and add it to the built-in “Administrators” group
  2. Set the HKLM/Software/Microsoft/Windows/CurrentVersion/Policies/System/LocalAccountTokenFilterPolicy (DWORD) to a value of 1 (you may need to add the LocalAccountTokeFilterPolicy DWORD value if it doesn’t exist). See http://support.microsoft.com/kb/942817/en-us for more details. 

Once you can do that you can use a Enter-PSSession or Invoke-Command with the credentials you created to remotely run PowerShell scripts against the target machine.

And yes, this applies to remoting into Azure Virtual Machines as well.  Just be aware that for Azure VMs you will need to import the certificate for the remote VM before you can successfully authenticate. 

For more info, check out Michael Washam’s “Introduction to Remote PowerShell with Windows Azure” and Jennelle Crother’s “The Imperfect Lab: Letting Additional Administrators Remotely Connect to Servers” .

Bret’s 70-532 MVA JumpStart Demo Files…

I’m presenting the Developing Microsoft Azure Solutions MVA (http://www.microsoftvirtualacademy.com/liveevents/developing-microsoft-azure-solutions) with Sidney Andrews today (12/19/2014).

We’ll be covering a number of topics:

  1. Azure Web Sites
  2. Cloud Services
  3. Virtual Machines
  4. Azure SQL Database
  5. Storage Services
  6. Application Architecture

Specifically, I’m covering the even numbered modules, on Cloud Services, Azure SQL Database, and Application Architecture.

You can grab a copy of my demos from http://aka.ms/BretsMVA532Demos .  Make sure to restore the NuGet packages in each solution.

Enjoy1

Azure Hackathon Resources

At a Hackathon?  Need quick access to some “Azure How To’s to get you started?” Here are some links.  These resources are just to get your started.  If you need something more in depth, check out “Microsoft Virtual Academy

  1. Windows Azure Pass Usage Tutorial if you don’t have an Azure Pass code, you can always create a free trial
  2. Azure Documentation – Everything you need to know about Microsoft Azure
  3. Quick 3-Minute getting started with Azure videos
  4. Creating a Windows Virtual Machine in Azure – Azure Virtual Machines are a great way to get started with the cloud
  5. Creating a Linux Virtual Machine in Azure – Yep! You can create Linux VMs in Azure.   You can also learn how to install the LAMP stack on your Linux VM 
  6. Create a Node.JS Website in Azure and Deploy from GitHub – Azure websites support the platforms you love like ASP.NET, PHP, Python and Node.js and you can deploy from source control services like Visual Studio Online or GitHub
  7. Visual Studio Online – You can create FREE, PRIVATE projects in Visual Studio Online.  Get more than just source control.
  8. Create an Azure Mobile Service for your Android App – Azure Mobile Services are an extremely powerful way to create backends for your mobile apps!
  9. Create an Azure Mobile Service for your iOS App – And iOS apps
  10. Create an Azure Mobile Service for your HTML5 Client App!
  11. Getting User Data with Azure Mobile Services

“DevTest Scenarios in the DevOps World” Resources

Today, 10/20/2014 Cale Teeter, Charles Sterling, Jeff Levinson and I will be delivering a live session on Microsoft Virtual Academy on “Dev/Test Scenarios in the DevOps World”. 

You can grab a copy of Bret’s Demo Files here: http://1drv.ms/1r0CFJw

Spark Core enabled Compressed Air Rocket Launcher

Earlier this month some teammates and I were lucky enough to participate in TechCrunch Disrupt Hackathon in San Francisco

SNAGHTML16ced63

Our team project was called “Notifly” and was an online social media aggregation and activation platform.  In the end, we used it to watch a twitter hashtag, and launch a compressed air rocket when a threshold was crossed! We used a Spark Core from Spark.with a Relay Shield to activiate the rocket via a REST API!  Super cool Here’s a pic of everything assembled. 

image

Anyhow, if you would like to build your own, you can find the instructions for doing so on github at http://github.com/dxdisrupt/rocket

SNAGHTML1802406

Dollar Store Food Containers Make Great Project Enclosures…

At the end of summer when my kids were in need of school supplies, we ended up passing through the local dollar store to find a few things. Right next to the pencil boxes and binders were plastic food containers for the kids to bring lunches and snacks to school in.  As soon as I saw them, I realized they would make fantastic project enclosures!  Here is the dollar sandwich container housing a Spark Core and a Relay Shield for my Compressed Air Rocket Launcher (I didn’t have a 9V battery clip on me when I put this together so the pink bubble wrap is there to keep the battery from knocking around):

image

The even smaller “snack” size boxes came in packs of three for $1.  Each one is a perfect (well, maybe a little tight) enclosure for an Arduino Uno with a a Shield and a 9V battery:

image

The one thing you do need to look out for is that sometimes the plastic can crack when you are drilling holes, so take your time, go slow.  And if you end up breaking one, it was only a buck!

Also, I went back just the other week, and the “back-to-school” stock has been pulled and replaced with Halloween items.  I couldn’t find these containers in my local dollar stores any more. There were others, but I didn’t like them as well.  However with some searching, I was able to find some online on dollartree.com

Just ordered my Edison!

I’ve been having a ton of fun with my Intel Galileo Blog Posts, but I have been anxiously awaiting the Intel Edison, a much smaller, but still “arduino compatible” development board.  On September 9, at the Intel Developer Forum (IDF) Intel announced the Edison, and showed off a lot of cool things you can do with it.

I just jumped on SparkFun and ordered both the Edison with the Arduino Breakout Kit as well as the Edison with the Mini Breakout Kit and some of the SparkFun “Blocks”.  Now I just have to wait 6-8 weeks to get them (fingers drumming on table).

Intel® Edison and Arduino Breakout Kit

Shutting Down Your Intel Galileo running Windows

UPDATED ON 09/10/2014 – Added remote shutdown info

On the “Setting up your Galileo” page, at the very bottom, there is a strong recommendation to shutdown your Intel Galileo running Windows.  The promise is that if you properly shutdown the Galileo, as opposed to just pulling the power cord, or hitting the “Reboot” button, you will experience shorter boot times.  I can confirm this personally after having rebooted my Galileo’s repeatedly, using all of the methods, over the past few days.  If you can connect to your Galileo via Telnet, and shut it down formally, it will boot much quicker next time. 

Here is a repeat for the instructions from the “Setting up your Galileo” page:

Shutting down the Galileo

Before you unplug the power from the Galileo, it is advisable to gracefully shut it down. To do this:

  1. Telnet to the Galileo
  2. Enter the following command to shutdown:
    shutdown /s /t 0

After the microSD activity LED stops blinking, you may unplug the Galileo.

NOTE:

If you do not shut the Galileo down, the next boot will take much longer. During this time, Windows will run a check disk on the SD card to verify the integrity of the file system. Please allow this to finish.

Shutting down the Galileo REMOTELY

This morning, I started to think about shutting it down remotely.  Not a big deal.  Windows admin do remote shutdowns all the time, and it is no different with the galileo.  You just need to authenticate against the galileo before you run the shutdown command against it.  I created a batch file called “bouncegalileo.cmd” that let’s me do that easily.  Here are the contents of the batch fi8le:

@ECHO OFF
REM
REM USAGE: bouncegalileo.cmd <galileoname>
REM Where <galileoname> is the host name of your galileo
REM
REM First, remove any existing connections to the galileo
net use \\%1 /del
REM Now, authenticate against the galileo as the Administrator
net use \\%1 /user:Administrator
REM Then use the shutdown command to restart the galileo immediately
REM The /r causes the galileo to RESTART.  Use /s to SHUTDOWN
shutdown /m \\%1 /r /t 0

Wrap that up in a batch file (I called mine “bouncegalileo.cmd”) and then the call to it would look something like this:

image

You can monitor your Galileo’s status in the “GalileoWatcher” .  It should take minute or so to come back on line.

SNAGHTML491e103

Getting Started with Windows on the Intel Galileo (Gen 1)

This is the second video in my Intel Galileo Series.  In this video, I show you how to get the free version of Windows from the Windows Developer Program for IoT running on your Intel Galileo Gen 1 board.

Here are some handy links for this video:

You can get the source files for the entire series from:
http://aka.ms/IoTSource

Or download a .zip file with the latest version of the files from:
http://aka.ms/IoTZip

And finally, watch all the other videos here:
http://aka.ms/IoTVids