IT Consultant Everyday Notes

Just some problems/solutions storage

Monthly Archives: December 2014

Azure Automation: Send Email from Azure Automation Script via GMAIL

I am working with Azure Automation scripts. One of them stops all my Lab VMs after working hours to save some money. Script is based on one from Automation Gallery, but I wanted to add a notification feature.

There are several posts about using O365 for this, but I do not think it is a good idea since 0365 is not free.

I tried (AKA Hotmail) first, trying to stick with Microsoft platform, but did not get any success (authentication kept failed for me). So, the second choice was From some posts I understood Azure does not have root certificates from GMAIL CA and SSL connection does not work. To workaround the issue I downloaded Google root certificate and created a Certificate Asset in Automation console


Interesting enough I do not need to use it in my script apparently simply existence of it is enough….

Here is the script to check if all machines are in stop(Deallocated) state and send email otherwise. The script uses a PS Credential Asset: ‘Azure Credentials’ and my MSDN Platform subscription.

I created a test account at Gmail: and add an Automation Asset (PS Credentials) including Gmail user name and password – “Gmailcreds” that allows do not put user name/password in the script.

workflow test-mail
   $Cred = Get-AutomationPSCredential -Name ‘Azure Credentials’
   $Gmailcreds = Get-AutomationPSCredential -Name ‘Gmailcerds’
   Add-AzureAccount -Credential $Cred
   Select-AzureSubscription -SubscriptionName “MSDN Platforms”   
   $vms = Get-AzureVM
   ForEach ($vm in $vms ) {
      if ($vm.Status -ne “StoppedDeallocated”) {$ss=$ss+$” – “+$vm.Status + “`r`n”}
   if ($ss -ne “”) {
      $mail_body= ‘Attention! One or more VMs are in a state other than “Stopped (Deallocated)”‘ `
      Send-MailMessage -SmtpServer -Port 587 -Credential $Gmailcreds `
         -UseSsl -From ‘’ -To ‘’ `
         -Subject ‘Alarm: Azure Automation – Running VM!’ -body $mail_body

This script can be added to schedule to run every night.

Server 2003: Migration to Azure

In my test Lab I migrated Server 2003 VM to the Cloud. The matter in fact it is not enough just copy VHD to Azure using

Add-AzureVhd [-Destination] <Uri> [-LocalFilePath] <FileInfo> [[-NumberOfUploaderThreads] <Int32> ] [[-BaseImageUriToPatch] <Uri> ] [[-OverWrite]] [ <CommonParameters>]

command in Azure PowerShell

It as also necessary to add the copied disk to inventory using:

Add-AzureDisk [-DiskName] <String> [-MediaLocation] <String> [-Label <String> ] [-OS <String> ] [ <CommonParameters>]

In my case the script looks like



The information was found in Sandrino’s blog here:

Lync: Script: Get-CsConnections.ps1 – See User Connections, Client Versions, Load Balancing in Lync Server

An old script, but never saw it before for some reasons – it allows to see Client versions and user distribution per Front-end Server. I use it during FE updates, to be sure there is no user connected to an updated FE.

original is here