Skip to content

Instantly share code, notes, and snippets.

@joerodgers
Created October 5, 2017 19:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joerodgers/d645ebaadc622091149bf864fa3e91d5 to your computer and use it in GitHub Desktop.
Save joerodgers/d645ebaadc622091149bf864fa3e91d5 to your computer and use it in GitHub Desktop.
Download the latest O365 URL and IP Address Updates to a CSV
function Get-Office365UrlandIPAddressUpdates
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$false)][int]$Days = -7
)
begin
{
$firstChunk = $true
$updates = @()
# make sure the days is negative
if( $Days -gt 0 ) { $Days = $Days * -1 }
}
process
{
$request = Invoke-WebRequest -Uri "https://support.office.com/en-us/o365ip/rss"
$xml = [xml]$request.Content
$xml.rss.channel.item | ? { ([DateTime]$_.Pubdate) -gt (Get-Date -Hour 0 -Minute 0).AddDays($Days) } | % {
$firstChunk = $true
$sb = New-Object System.Text.StringBuilder
$descriptionChunks = $_.Description.Replace("`n", " ").Split(",")
foreach( $chunk in $descriptionChunks )
{
if( $firstChunk )
{
$firstChunk = $false
# Adding 1 FQDNs; 1/[Effective 6/1/2017. Required: Skype for Business. ExpressRoute: No. skypegraph.skype.com]. Notes: Correcting the previously incorrect SkypeGraph FQDN.
if( $chunk -match "(?<UpdateType>.*);\d*\s*.*\[Effective\s(?<Date>\d+\/\d+\/\d+).\s*.*:(?<Product>.*). ExpressRoute: (?<ExpressRoute>.\w*).\s*(?<IPAddress>.*)\](.*Notes:(?<Notes>.*))?" )
{
$obj = [PSCustomObject] @{
UpdateType = $Matches["UpdateType"]
Date = $Matches["Date"]
Product = $Matches["Product"]
ExpressRoute = $Matches["ExpressRoute"]
EndPoint = $Matches["IPAddress"]
Notes = $Matches["Notes"]
}
$sb.AppendLine( "Update Type: $($($obj.UpdateType))`n`nEffective Date: $($obj.Date)`nProduct: $($obj.Product)`nExpress Route: $($obj.ExpressRoute)`nIPAddress: $($obj.EndPoint)" ) | Out-Null
if( $obj.Notes)
{
$sb.AppendLine( "Notes: $($obj.Notes)" ) | Out-Null
}
}
# Removing 1 FQDNs 1/[Effective 6/1/2017. Required: Skype for Business. ExpressRoute: No. graph.skype.com]. Notes: Correcting the previously incorrect SkypeGraph FQDN.
elseif( $chunk -match "(?<UpdateType>.*)\d\/\[Effective\s(?<Date>\d+\/\d+\/\d+).\s*.*:(?<Product>.*). ExpressRoute: (?<ExpressRoute>.\w*).\s*(?<IPAddress>.*)\](.*Notes:(?<Notes>.*))?" )
{
$obj = [PSCustomObject] @{
UpdateType = $Matches["UpdateType"]
Date = $Matches["Date"]
Product = $Matches["Product"]
ExpressRoute = $Matches["ExpressRoute"]
EndPoint = $Matches["IPAddress"]
Notes = $Matches["Notes"]
}
$sb.AppendLine( "Update Type: $($($obj.UpdateType))`n`nEffective Date: $($obj.Date)`nProduct: $($obj.Product)`nExpress Route: $($obj.ExpressRoute)`nIPAddress: $($obj.EndPoint)" ) | Out-Null
if( $obj.Notes)
{
$sb.AppendLine( "Notes: $($obj.Notes)" ) | Out-Null
}
}
else
{
$sb.AppendLine( $chunk ) | Out-Null
}
}
elseif ($chunk -match ".*\[Effective\s(?<Date>\d+\/\d+\/\d+).\s*.*:(?<Product>.*). ExpressRoute: (?<ExpressRoute>.\w*).\s*(?<IPAddress>.*)\](.*Notes:(?<Notes>.*))?")
{
$obj = [PSCustomObject] @{
Date = $Matches["Date"]
Product = $Matches["Product"]
ExpressRoute = $Matches["ExpressRoute"]
EndPoint = $Matches["IPAddress"]
Notes = $Matches["Notes"]
}
$sb.AppendLine( "`nEffective Date: $($obj.Date)`nProduct: $($obj.Product)`nExpress Route: $($obj.ExpressRoute)`nIPAddress: $($obj.EndPoint)" ) | Out-Null
if( $obj.Notes)
{
$sb.AppendLine( "Notes: $($obj.Notes)" ) | Out-Null
}
}
else
{
$sb.AppendLine( $chunk ) | Out-Null
}
}
$updates += [PSCustomObject] @{
SortDate = [DateTime]::Parse($_.PubDate)
"Product Family" = $_.Title.Replace("`n", " ")
"Publication Date" = [DateTime]::Parse($_.PubDate).Tostring("MM-dd-yyyy")
"Reference Link" = $_.Link
"Update Details" = $sb.ToString()
}
}
}
end
{
$updates | SORT SortDate -Descending | SELECT "Publication Date", "Product Family", "Update Details", "Reference Link"
}
}
Get-Office365UrlandIPAddressUpdates -Days 10 | Export-Csv -Path "C:\_temp\O365UrlAndIPAddressUpdates.csv" -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment