PowerShell Automation

Working with Azure Accounts


Connecting to Azure with Powershell


You'll need to download and install the Azure Powershell Module.

This command will import the Azure module into a regular powershell session
Import-Module Azure


This command will prompt you to signin with an Azure Account.

Method 1 (Preferred):
Add-Account


This command directs you to the Publishing Settings web page where you can download an encoded management certificate, which contains secure credentials and additional information about subscriptions that can be used in various ways including a development environment. Once you've received the file, the encoded credentials can be imported over and over to access your environment.

Anyone with access to this file can access your environment and make changes that portal administrators can

Method 2 :

Get-AzurePublishSettingsFile


Imports a publish settings file. Once imported you'll be able to manage your Azure accounts in Windows PowerShell.

Import-AzurePublishSettingsFile

Updating the Azure VM Guest Agent

For Classic VMs, aka Iaas v1, you'll be using the Azure Powershell Module.

Step 1

Open up the Azure Powershell Module

Step 2

Add your Azure Account or Select an Azure Subscription to work with.

Add-AzureAccount 
or
Select-AzureSubscription

Step 3

Get the Agent Status

# Define the VMName Variable
#Select a VM and insert the Name into the VMName variable below.
$VMName = 'UbuClassicTest'

# Define the VM Variable and gather the VM Properties
$VM = Get-AzureVM | ?{$_.name -eq $VMName}

# Use the VM Properties to 
$VM.guestagentstatus

Results should look similar to these:
ProtocolVersion   : 1.0
TimestampUtc      : 3/4/2016 2:57:25 AM
GuestAgentVersion : 2.7.1198.735
Status            : Ready
Code              :
Message           :
FormattedMessage  : Microsoft.WindowsAzure.Commands.ServiceManagement.Model.GuestAgentFormattedMessage

Step 5

Get the Agent Status Message

$VM.guestagentstatus.formattedmessage

Results should look similar to these
GuestAgent is running and accepting new configurations.

Step 6

In some cases you will need to restart the guest agent from within the VM. Otherwise, you may need to reinstall or install the latest version before running the command below.

$VM.ProvisionGuestAgent = $true
$VM | Update-AzureVm

Links:

Azure SLT Labs