Connect to an Azure Virtual Machine

This PowerShell Workflow runbook sets up a connection to an Azure virtual machine.

 
 
 
 
 
4.6 Star
(7)
13,028 times
Add to favorites
Windows Azure
5/18/2016
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Going the other direction...
    1 Posts | Last post March 24, 2017
    • This looked promising at first, but I need the cert to go in the opposite direction...that is, my VM already contains a certificate in its local store, and I want to upload that certificate into Azure as an automation asset.
      
      I can get to the VM with Get-AzureVM, and I can see its .VM property contains a DefaultWinRmCertificateThumbprint, which is a string I've confirmed matches the cert I want to upload.  It's also got a WinRMCertificate property, but it's null.
      
      I realize I can get the cert from a script running *inside* the VM with:
      
      Get-ChildItem -Path Cert:\LocalMachine\My
      and then
      Export-Certificate [...]
      ...but I'm trying to do this at a large scale (dozens, perhaps hundreds of VMs), and some of them might even be turned off.  Remoting *into* them is simply not practical.
      
      Is there not a property associated with the VM object that can get me the full cert object that I could then upload to Azure?
      
  • What is the "service name"?
    1 Posts | Last post August 16, 2016
    • Using the new Azure portal, we have created a virtual machine that has no DNS name.  Providing the IP address for the Service Name parameter in this workflow doesn't work.  What should I provide for the Service Name parameter?
      
      I can see the following in the portal for this VM:
      Resource group, 
      computer name, 
      status, 
      operating system, 
      location, 
      size, 
      subscription name, 
      Public IP Address/DNS name label (the IP address displays, but the label is "<none>"), Subscription Id (a GUID), 
      Virtual network/subnet
  • How without Azure AD connect to the VM for run script?
    1 Posts | Last post May 19, 2016
    • Hi. all.
      I`m don`t understand - how to run in the VM script( cmd or powershell) from the Azure Auromation  ?  ( without use AZure AD) 
      
      Serg
  • Connect to the Azure VM via internal endpoint/Vnet
    1 Posts | Last post January 26, 2016
    • Can anyone help with leveraging a connection over a internal endpoint rather than a public endpoin using this template? I want to be able to connect to my Azure VM internally. 
  • CertificateThumbprint on VM built from a disk
    1 Posts | Last post March 04, 2015
    • I'm writing a script to automate some action on several azure VM.
      
      I try to connect to the machines using your script, but it fails on some machines, saying "the argument on parameter "Thumbprint" can't be validated".
      I discovered this happens for virtual machines built from a disk, and not from an image.
      
      Any idea how I can connect to this machines ?
  • AzureConnectionName ?
    2 Posts | Last post December 13, 2014
    • When calling this via BackupAzureVM script ( https://gallery.technet.microsoft.com/scriptcenter/Back-up-an-Azure-VM-using-9545f0a1 ) I'm getting the following error:
      
      At line:159 char:8 + $Uri = Connect-AzureVM -AzureConnectionName $AzureConnectionName -serviceName $S ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Could not find a parameter named 'AzureConnectionName'.
      
      (The script isn't even 159 lines so I'm all sorts of confused) 
      
      Any idea how I can get around this?
    • We have updated the Connect-AzureVM runbook to use OrgId Authentication and it looks like the BackupAzureVM uses an outdated version of this runbook. OrgId is the recommended way of connecting to Azure now:  http://azure.microsoft.com/blog/2014/08/27/azure-automation-authenticating-to-azure-using-azure-active-directory/
      
      To make the updates:
      1. Edit the BackupAzureVM runbook
      2. Replace the $AzureConnectionName parameter with $AzureAdOrgIdName parameter
      3. Retrieve your Azure OrgID from the Asset store
      4. Click Insert > Runbook > Connect-AzureVM to get the correct parameters to pull the $URI and update the variables (this replaces the existing Connect-AzureVM call).   The correct parameters will be included.
      
      
      Here is an example of an updated version of the BackupAzureVM following the steps above:
      
      
      workflow BackupAzureVM
      
      {
      
      Param
      
      (
      
      [parameter(Mandatory=$true)]
      
      [String]
      
      $AzureOrgIdCredentialName,
      
      [parameter(Mandatory=$true)]
      
      [String]
      
      $ServiceName,
      
      [parameter(Mandatory=$true)]
      
      [String]
      
      $VMName,
      
      [parameter(Mandatory=$true)]
      
      [String]
      
      $StorageAccountName,
      
      [parameter(Mandatory=$true)]
      
      [String]
      
      $backupContainerName
      
      )
      
      # Set up Azure connection by calling the Connect-Azure runbook, found in my previous post.
      $Cred = Get-AutomationPSCredential -Name $AzureOrgIdCredentialName
      $Uri = Connect-AzureVM `
              -AzureOrgIdCredential $Cred `
              -AzureSubscriptionName "MySubscription" `
              -ServiceName $ServiceName `
              -VMName $VMName
      
      # Stop Azure VM
      
      Stop-AzureVM -ServiceName $ServiceName -Name $VMName –StayProvisioned
      
      # Backup Azure VM
      
      Backup-AzureVM -serviceName $ServiceName -VMName $VMName -backupContainerName $backupContainerName -backupStorageAccountName $StorageAccountName –includeDataDisks
      
      # Start Azure VM
      
      Start-AzureVM -ServiceName $ServiceName -Name $VMName
      
      }