Skip to content

Instantly share code, notes, and snippets.

@vijayjt
Last active July 31, 2017 12:25
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save vijayjt/867ba1ddbfc38f03a14149584a1e80bc 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