Azure, PowerShell Kieran Jacobsen Azure, PowerShell Kieran Jacobsen

AzurePublicIPAddresses v1.0 has been released

I'm pleased to announce Version 1.0 of AzurePublicIPAddresses. This version includes support 6 new Azure regions:

  • Australia Central

  • Australia Central 2

  • UK North

  • UK South 2

  • North Europe 2 (name TBC)

  • East Europe (name TBC)

This release also represents a major milestone since the modules creation back in March 2016. The module has proven to be very stable, and hence I'm now giving it the stable 1.0 moniker. I'm confident that the existing design should support any new regions or source XML files that Microsoft may release without the need for breaking changes.

I'm pleased to announce Version 1.0 of AzurePublicIPAddresses. This version includes support 6 new Azure regions:

This release also represents a major milestone since the modules creation back in March 2016. The module has proven to be very stable, and hence I'm now giving it the stable 1.0 moniker. I'm confident that the existing design should support any new regions or source XML files that Microsoft may release without the need for breaking changes.

What's the future for this module? With the launch of Azure Service Tags, in some respects this module has become less useful, but, I'll maintain the module for the immediate future.

I'm also thinking how this module and the JSON based file for Azure Service Tags should fit together. My current through it to create a separate module that consumes that file and allows you to select addresses by region and service.

Getting the Module

If you have never used the module before, the easiest way to get AzurePublicIPAddresses is through the PowerShell Gallery:

PS> Install-Module -Name AzurePublicIPAddresses

If you already have the module installed, you can update the module from the PowerShell Gallery with:

PS> Update-Module -Name AzurePublicIPAddresses

You can also find the module on GitHub.

Found an issue? Then raise any bugs or feature requests via GitHub Issues.

Read More
Azure, PowerShell Kieran Jacobsen Azure, PowerShell Kieran Jacobsen

AzurePublicIPAddresses module now supports the France and Germany Azure Regions

I'm pleased to announce that my PowerShell for working with Azure’s public IP address listings now supports the new Azure Regions in France and Germany. This release, 0.9, introduces some minor breaking changes, needed to support the Germany regions.

Map of Azure Regions as of February 2018

Map of Azure Regions as of February 2018

I'm pleased to announce that my PowerShell for working with Azure’s public IP address listings now supports the new Azure Regions in France and Germany. This release, 0.9, introduces some minor breaking changes, needed to support the Germany regions.

Each month of so, I check the Microsoft Azure Datacenter IP Ranges file for new regions. This month, I noticed that the France Central and France South are included.

The Azure Germany regions, Germany Northeast and Germany Central, are managed under a trustee model by T-Systems. This is like that of Azure in China. I hadn’t seen the German regions IP ranges before, but last week I found the file: Windows Azure Datacenter IP Ranges in Germany. My goal always was to support every available Azure Region, as such, I've now included these regions.

I must admit, I didn’t fully design this module to be future proof, I assumed all regions would be included in a single file. I first included Azure in China in version 0.8, with the -ChinaRegion parameter. While functional, this wasn’t future proof. To offer support for Azure Germany, version 0.8 includes some breaking changes in the Get-MicrosoftAzureDatacenterIPRangeFile CMDLet.

With version 0.9, I've removed the -ChinaRegion parameter and replaced it with -Region. This new parameter takes one of 3 values: Standard, China or Germany. This parameter now has this behaviour:

If you were separately downloading the China region file, you'll need to ensure that you update your scripts logic.

I've also tweaked Get-MicrosoftazureDatacenterIPRange. The first change was to add support for the extra file to download, and the parameter change. I've also modified the logic around how the CMDLet stores the region information. I don’t expect these changes to cause any issues.

Getting the Module

If you have never used the module before, the easiest way to get AzurePublicIPAddresses is through the PowerShell Gallery:

PS> Install-Module -Name AzurePublicIPAddresses

If you already have the module installed, you can update the module from the PowerShell Gallery with:

PS> Update-Module -Name AzurePublicIPAddresses

You can also find the module on GitHub.

Found an issue? Then raise any bugs or feature requests via GitHub Issues.

Read More
Security, PowerShell Kieran Jacobsen Security, PowerShell Kieran Jacobsen

Sending SYSLOG messages to TCP hosts and POSH-SYSLOG V3.0

The Posh-SYSLOG module has been very popular since its first release in 2013. SYLOG provides a common integration point into enterprise monitoring, alerting and security systems and administrators and developers often need to push messages from their scripts and automation activities to a SYSLOG server.

There are two common pieces of feedback, TCP support and improving the performance. I am excited to announce a new version of POSH-SYSLOG, which introduces TCP support and a number of performance improvements.

Kudos must go to Jared Poeppelman (powershellshock) from Microsoft who provided the TCP logic, optimised performance, and added additional Pester cases. I took some time out to make some additional improvements on top of Jared’s work. Due to the significant changes and additional functionality, I am considering this to be version 3.0.

The easiest way to get the module is from the PowerShell Gallery using Install-Module -Name Posh-SYSLOG. You can also clone the GitHub repository.

The first big change by Jared, was to implement the Begin {} Process {} End {} structure for Send-SyslogMessage. With this structure, we can leverage the pipeline to send multiple messages. I have developed scripts where I needed to read application logs and then send them to a SIEM product using SYSLOG; access via the pipeline simplifies these scripts and hopefully improves their performance.

The logic around determining the correct value to be sent as the hostname has been cleaned up and refined. This piece was free of issues, however there were some small tweaks that potentially improved performance. The function is now called as part of the Begin {} block, improving performance for bulk message transmissions. The logic has been moved out to its own internal function, allowing for separate testing and better mocking opportunities in Pester.

Another source of performance improvement is the removal on the need to call Test-NetConnection. This is a dramatic source of improvement when Send-SyslogMessage is executed in a workgroup (that is, a non-domain joined) environment. Previously we called Test-NetConnection to determine the correct network interface that we are using to communicate with the SYSLOG server; now we simply ask the socket for the source IP address and then use Get-NetIPAddress to check if this is a statically assigned address.

All the network functionality and calls have been moved to internal functions. This helped with testing, I can now mock all the network activities which allows for better testing with Pester. The network tests are now much more reliable.

Finally, Jared and I have increased the number of Pester tests. I have tried to aim for over testing everything in the hope that all potential issues are flushed out. With a massive upgrade to the functionality, and such a refactoring have the potential to introducing issues. I am confident that things have been appropriately requested. If issues are found, please raise them via GitHub.

So what is the future now for Posh-SYSLOG? Well for now, I just want to ensure there are no bugs or issues, after that I want to look at implementing the other commonly asked feature; TLS support.

The PowerShell community has been amazing, I have been lucky to have such wonderful community contributions over the past few years. A massive thanks to Jared, Ronald, Xtrahost and Fredruk.

Kieran Jacobsen

Read More
PowerShell Kieran Jacobsen PowerShell Kieran Jacobsen

How Big Is That Subnet?

I recently had a long list of IPv4 CIDR addresses and wanted to know how many hosts there were in total. Looking at the list, there was a mix of common sizes, /29, /24 and /16 but there were a few I just don’t know off the top of my head. The list was long, and it would have be tedious work manually calculating each.

Get-SubnetSize

So, I did what any IT professional in my shoes would do, I wrote some code. The Get-SubnetSize CMDLet will return the total number of usable (often referred to as the number of host) addresses for a specified subnet.

By default, it doesn't count the subnet ID or the broadcast addresses, however, there is a switch -IncludeSubnetIDAndBroadcastAddress, to include those if need them included.

Working with Get-SubnetSize

To work out the size of the subnet 172.16.0.0/24, we simply call: Get-SubnetSize -CIDR 172.16.0.0/24 which will return 254.

Get-SubnetSize -CIDR ’172.16.0.0/24’

Get-SubnetSize -CIDR ’172.16.0.0/24’

What about if we had a subnet mask? Well we can work that out as well! How big is 255.0.0.0? Get-SubnetSize -Subnetmask 255.0.0.0 returns 16777214.

Get-SubnetSize -Subnetmask '255.0.0.0'

Get-SubnetSize -Subnetmask '255.0.0.0'

How many public IP addresses does Azure use?

Previously I have written about my AzurePublicIPAddresses module in my post, Working with Azure’s public IP addresses. This module allows you to obtain the public IP addresses available in each Azure Region. The module is updated for each new Azure Region that Microsoft introduces.

Combining Get-MicrosoftAzureDatacenterIPRange, Get-SubnetSize and Measure-Object together, we can create a one-liner that will give us the total number of subnets and IP addresses.

Get-MicrosoftAzureDatacenterIPRange | Select-Object -ExpandProperty Subnet | Get-SubnetSize | Measure-Object -Sum
Get-MicrosoftAzureDatacenterIPRange | Select-Object -ExpandProperty Subnet | Get-SubnetSize | Measure-Object -Sum

Get-MicrosoftAzureDatacenterIPRange | Select-Object -ExpandProperty Subnet | Get-SubnetSize | Measure-Object -Sum

And we can see that there are 2621 Subnets and a whopping 7,613,174 IP addresses!!

Getting the module

Posh-SubnetTools is available from the PowerShell Gallery or from the project’s GitHub page.

This module should work with all versions of PowerShell, including PowerShell Core. I have tested the module on PowerShell 5.1 (Windows 10 Insiders).

I appreciate any issues, pull requests or comments that you may have. Have an idea for a new CMDLet, make a pull request and I will include it!

Read More
PowerShell Kieran Jacobsen PowerShell Kieran Jacobsen

Working with Azure’s public IP addresses

If you have spent much time working with Microsoft Azure, Amazon AWS or any public cloud provider, you have probably started to wonder about how many public IPv4 addresses they have. Whilst we know there is a limit to the number of addresses, and that we have reached these limits, it still seems like there are quite a few to go around.

I recently had the need to get a listing of all the Azure subnets, and whilst I did this, I thought it would be good to make a reusable PowerShell module to assist.

Microsoft makes this process pretty easy, providing an XML file under the Microsoft Download Center title: Microsoft Azure Datacenter IP Ranges. There are a few things to note about this file:

  • It contains all compute (including SQL),
  • It is updated on Wednesday (Pacific Time), but changes are effective from the following Monday (Pacific Time), and,
  • The file will contain only production Azure DCs, for instance, at the time of writing the German and Canadian DCs are not contained in the file.

I have developed a PowerShell module that simplifies working with this file by developing CMDLets that:

  1. Allowing for automated downloads of the file, and,
  2. Allow for specific DCs to be extracted

Get-MicrosoftAzureDatacenterIPRangeFile provides us with a method to simply and easily access the XML document. If called without parameters, we will get the XML document returned, however we can opt to save the file to disk for future processing.

Then we have Get-MicrosoftAzureDatacenterIPRange. With this CMDLet, we can get a list of objects containing the subnets (in CIDR format) for a specific DC or for all of the DCs. You can specify the path to a previously downloaded file, or it can download the file for us (and keep it in memory).

The module can be found on:

I have tested this module against PowerShell 5, however there should be no issue with earlier versions (I recommend PowerShell 3 or higher). If you encounter any issues, please raise an issue on the GitHub page.

Just in case you were wondering, Azure has approximately 1700 subnets, or around 5.8 million IPv4 addresses!

Kieran Jacobsen

Read More