Last active
July 31, 2017 12:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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