Month: February 2017

Adding a Public IP to an Existing Azure ARM VM

If you are not running a jump host in your environment I find from time to time that I need to add a Public IP to a NIC and connect to my virtual machine.

PowerShell is by far the easiest way to complete this task. The small script below outlines how to do this.

# New-AzurePublicRmIAddress creates the new IP - Run this first. 

new-azurermpublicIPAddress -Name testip -ResourceGroupName wpbackup -AllocationMethod Static -Location "Southeast Asia"

# Set the variables but getting the properties you need 
$nic = Get-AzurermNetworkInterface -ResourceGroupName Nameof ResourceGroup -Name NameofNIC
$pip = Get-AzurermPublicIPAddress -ResourceGroupName wpbackup -Name testip
$nic.IPConfigurations[0].PublicIPAddress=$pip

# Finally set the IP address against the NIC
Set-AzureRmNetworkInterface -NetworkInterface $nic

Disclaimer:  Please note although I work for Microsoft the information provided here does not represent an official Microsoft position and is provided as is.

Audit number of VHDs per Storage Account | Azure

Time for some code.  I was recently asked by a customer to help them audit the number of active VHDs in a storage account.

As ever with a little digging around and some slight adjustment I was able to provide what they were after.

Original came from the very accomplished John Savill and was posted at Windows IT Pro.

$FindStorage = Get-AzurermStorageAccount 
$out = @()
 
Foreach ($Storage in $FindStorage)
{
$Name = $Storage.StorageAccountName
$ResourceGroupName = $Storage.ResourceGroupName
$Location = $Storage.Location

$AllBlobs = Get-AzureRMStorageAccount -Name $Name -ResourceGroupName $ResourceGroupName | 
    Get-AzureStorageContainer | where {$_.Name -eq 'vhds'} | Get-AzureStorageBlob | where {$_.Name.EndsWith('.vhd')} 

$VHDsinAct = 0

foreach ($Blob in $AllBlobs)
{

    if($Blob.ICloudBlob.Properties.LeaseState -eq 'Leased' -and $Blob.ICloudBlob.Properties.LeaseDuration -eq 'Infinite')
    {        
        $VHDsinAct++ 
    }
}

$props = @{

StorageAccount = $Name
VHDs = $VHDsinAct
ResourceGroup = $ResourceGroupName
Location =$Location
}
 #Write-Output "Total of $VHDsinAct VHDs in $Name"
 $out += New-Object PsObject -Property $props
}

$out | Format-Table -AutoSize -Wrap  StorageAccount, VHDs, ResourceGroup, Location 
$out | Out-GridView -Passthru

Disclaimer:  Please note although I work for Microsoft the information provided here does not represent an official Microsoft position and is provided as is.

Successfully Working from Home

I’ve learnt quite a bit about working from home in the last ten years and thought is was about time I shared one of the secrets to my success.

It will take longer to get used to than you will first admit. 

Working from home has some obvious benefits; no travel time, no interruptions, working all day in your pyjamas. It’s a breeze right? When I look back I can honestly say it took me over a year to get into the correct rhythm.  I had started a new job, I had a new baby (our first), I was sent a laptop, filing cabinet (don’t why I got that), chair, printer, tech. toys and I was away.  I knocked off what I thought was a day’s work by morning tea and was a very happy man. But how do you get by with no interaction with anyone at work? Monday is great but by Wednesday, outside of the odd phone call and customer conversation, who do you have the work chat with? What happens if you get frustrated at work and the next person you see is your new child or sleep deprived partner?  You suddenly need to slip out of work mode and into home mode, then back again.  You think Superman makes a fast change in a phone box, it’s nothing compared to mental gymnastics of the accomplished home worker.

As you get used to the transition you’ll be telling everyone how great life is but some times you’ll be doing this to convince yourself, more than anyone else. But working from home can be very rewarding and productive. It took me a while to work this out as I am not someone that has had much interest in physiology but you need to train your brain.

What did I do? I decided I had to identify in my mind where and when I was at work.  I picked a space and made sure everything was the same each time I started.  I created a routine of work, emails, calls and customer visits that I stuck to. I even cleaned and tided the space every week and set it up for Monday. I mentally told myself when I leave this spot I am no longer at work, I am at home. I moved a chair by the door and said to myself, work goes there when I leave this room. Over about twelve months I began to surprise myself with how quickly I was able to mentally switch roles.  I could stride through the house be dad, walk into my work space, sit down and get straight back into it. It was at this point working from home truly became great and productive.  

Without knowing it I was taking my brain through a series of mental exercises.  My brain was getting a workout and learning how to flip modes very quickly.

I have switched companies now and at Microsoft I have the flexibility to work at the office or at home. I can spend weeks in the office environment or at customer sites an then a period at home and the mental flexibility is still there. All I have to do is remember to get dressed when I go into the office.

This is a skill I’m sure anyone can learn.  I’d be interested in what makes working from home a success for you. I always say we all learn by sharing and if you have found another way don’t be shy, let the world know.