What is your Virtual Function?
This is a short article to show you how to use OMS Log Analytics to query the status of patches on Microsoft Windows Server platforms.
Please note: Official guidance and advice can be found here Protect your Windows devices against Spectre and Meltdown. This article is just one example of how to monitor patch status using the super cool OMS Log Analytics tools.
If you have not used OMS or Log Analytics it is well worth spending some time investigating. You have the option of paid, trial and free tiers and a whole range of interesting preconfigured packs to play with.
Where Log Analytics gets interesting is when you start to increase the amount of information you are gathering and then use custom queries to dig for information, provide proactive notifications and automated actions and to train and develop models to display insights into your environment. Just imagine a machine learning model applied to data from your sys log server to map our network activity and threats.
Head to your OMS Workspace that hosts your LogAnalytics Service for the VMs you want to monitor. At this stage it’s worth noting that there are a number of architectural options when considering your OMS Workspace design. This article does not go into the patterns you can adopt but as long as you have some VMs on premises being monitored and the data being collected you’ll be able to continue.
When the Advanced Analytics page has loaded open a new tab and paste in the query you need for the results you are after. To test select Run.
The query you are looking to run is from the Update data. Therefore this needs to be your first input. You are then extracting data from here and narrowing down what you are looking for. Once narrowed down you need to decide how you want this data displayed, this is your summary. Finally we are placing all this information into a table.
If this is the very first time you have tried a free form query try the top most line first. Its likely you will get a lot of records but you will see all the data and then be able to narrow it down to what you are after.
I have copied the query below for you to use. Like everything if you know a better of of doing things please share I’d certainly be interested!
| where KBID == "4056898" or KBID == "4056890"
| where UpdateState == 'Installed' or UpdateState == "Needed"
Disclaimer: Please note although I work for Microsoft the information provided here does not represent an official Microsoft position and is provided as is.
Having read Paulo Marques article Working with Azure Storage Tables from PowerShell I decided to make the edits to my auditing scripts and push the results into Azure Tables to act as a repository I have the ability to keep but also one that gives me more options. Moving forward we can look to update or pull this information out on demand or use it as a basis of a comparison. I find it quite useful to have an independent record of the starting and end state of an environment pre and post any work undertaken.
There are a number of ways you can audit an Azure environment. With most of my customers I have implemented OMS, often using a combination of paid and free tiers to achieve the reporting they need to meet their own requirements and standards.
I’m a big fan of OMS, this script represent only one way to gather information and a chance to try something new in PowerShell.
To get started you’ll need to follow the instructions in Paulo’s article to install the correct module and from there I suggest following his guide as this will give you a good understanding how the commands operate. Once competed it is a straight forward process to integrate this in to any auditing script you currently have. The example below already has a table created.
This second example updates the values in the Azure Table. To do this we have to pull out the Computer / Server status from the Table and add this to the collected information as before.
$subscriptionName = "Wade - Internal Consumption"
Remember there is always a better way to do things and the only way we find out is if you have a go at sharing. I look forward to your versions and updates. Happy scripting!
If you are looking to use Azure Disk Encryption and Azure Backup you need to follow a couple of additional steps to the standard encryption procedure.
Encrypt an Azure Virtual Machine Please note this will only encrypt the machine with BEK (BitLocker Encryption Key). This is not supported by Azure Backup.
Azure Disk Encryption for Windows and Linux IaaS VMs This procedure shows you how to enable and use a Key Encryption Key, that enables Azure Backup to work with BEK encrypted machines.
There are two types of encryption keys to consider.
The encryption service uses Key Vault to manage the secrets, to do this we need an application in Azure AD that has permissions (Set by a Key Vault Access Policy) to operate inside of Key Vault.
This is used if you are just using BEK or setting up KEK for Azure Backup support.
For KEK a Key must be imported or created in the Key Vault. You reference this key when running the commands.
Finally, the Backup Management Service needs permissions to access the Key Vault and the keys.
Please note: You will need a Key Vault before you can complete this procedure. The Key Vault must be in the same region as the VM that will be encrypted.
In Azure Active Directory, select App registrations and create a new app registration. Enter a Name, select Web app / API and assign a sign-on URL (you will not use this so a default entry is adequate).
Make a note of the Application ID and create and take note of the application Key. Please note that the Key will only be available to you after it is saved and only once on the page. After that it will be hidden.
In the Key Vault set up an Access Policy for the new application.
Key Permissions need to be set to Wrap Key, Secret permissions to Set.
Select Access Policies and from the template select Azure Backup. The principal will be Backup Management Service.
5. Check the Advanced access policies to enable access to Azure Disk Encryption for volume encryption.
$RGName = "RESOURCE GROUP NAME"
$AADClientID = "AZURE AD APPLICATION ID"
$AADClientSecret = "AZURE AD APPLICATION SECRET"
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"
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.
#Write-Output "Total of $VHDsinAct VHDs in $Name"
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.
Consultants love to audit environments and there is no better use of a script than for this purpose.
This script lists out the virtual networks and subnets in a subscription.
Remember there is always a better way to do things and if you have a better way don’t forget to share.
Please see post Hybrid Use Benefit HUB | Azure for details on the Microsoft HUB process.
I have been using a slight edit on the process described so thought I would place the code I have been using below.
Please note HUB images are now available in Azure, therefore a generalised image is no longer required.
Add-AzureRmVhd -ResourceGroupName $rgName -Destination $urlOfUploadedImageVhd -LocalFilePath "C:\Source\imagename.vhd"
$vmName = "Name of VM"
$StorageAccount = Get-AzureRmStorageAccount -ResourceGroupName $RGName -name "Resource Group Name"
I was recently asked to quickly audit a customer’s environment for all running VMs. I quickly reached for my PowerShell toolbox and put together the following script.
In the example below I have used the table grid views available. It would be just as easy to push all this info to a csv file. For swiftness this was my approach, I’d be very interested to hear from the gurus out there to see what your preference is and how you would do this.
Remember there is always a better way, just don’t keep that to yourself!