Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbramwell/8246ec0f508977d18040b32cb3ac27bc to your computer and use it in GitHub Desktop.
Save rbramwell/8246ec0f508977d18040b32cb3ac27bc to your computer and use it in GitHub Desktop.
PowerShell function to download the Azure Public IP Ranges file and save it locally
Function Get-AzurePublicIPRangesXMLFile
{
<#
.SYNOPSIS
This function downloads the Azure IP ranges XML file to the current directory or a specified path.
.DESCRIPTION
This function downloads the Azure IP ranges XML file to the current directory or a specified path.
.PARAMETER AzureIPRangeURL
An optional parameter that is the URL to the Azure IP range XML file download page.
.PARAMETER DestinationPath
The locaiton on the local filesystem where the Azure IP range XML file is to be downloaded.
.EXAMPLE
Get-AzurePublicIPRangesXMLFile -DestinationPath C:\AzureIPXMLFiles\
Get-AzurePublicIPRangesXMLFile -DestinationPath C:\AzureIPXMLFiles\ -AzureIPRangeURL 'https://www.microsoft.com/en-gb/download/confirmation.aspx?id=41653'
.NOTES
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false,HelpMessage='Enter the URL for the Azure IP range XML file')]
[String]$AzureIPRangeURL = 'https://www.microsoft.com/en-gb/download/confirmation.aspx?id=41653',
[Parameter(Mandatory=$true,HelpMessage='Enter the path where the XML file should be written')]
[ValidateScript({ Test-Path $_ })]
[String]$DestinationPath
)
If( $null -eq $AzureIPRangeURL ) { $AzureIPRangeURL = 'https://www.microsoft.com/en-gb/download/confirmation.aspx?id=41653' }
$AzureIPRangePage = (Invoke-WebRequest -UseBasicParsing -Uri $AzureIPRangeURL )
$AzureIPRangeXMLFileURL = (($AzureIPRangePage.Links | Where-Object { $_.href -like "*PublicIP*xml" }).href)[0]
Write-Verbose "Azure IP Range XML File URL is $AzureIPRangeXMLFileURL"
Invoke-WebRequest -UseBasicParsing -Uri $AzureIPRangeXMLFileURL -OutFile "$DestinationPath\AzurePublicIPRanges.xml"
}#EndFunction Get-AzureIPRangesXMLFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment