Saturday, May 11, 2024
HomePowershellPowerShell is enjoyable :) Take a look at if Microsoft providers TCP...

PowerShell is enjoyable :) Take a look at if Microsoft providers TCP ports are accessible


In a earlier weblog submit, I confirmed a solution to retrieve all of the Microsoft Providers FQDNs, ports, and IP-Addresses. Good to know these in safe environments the place not the whole lot is allowed to go onto the web, however how will you take a look at if they’re accessible? This weblog submit will present the best way to take a look at most of those providers utilizing PowerShell.

How the script works

It makes use of the identical technique I utilized in this weblog submit to retrieve essentially the most present checklist of providers, it then checks for all of the URLs in it and tries to hook up with every TCP port. On-screen, whereas working the script, it can present the progress of the scan and can output it to an Out-GridView display screen or to a CSV file if specified.

Observe: There are a couple of UDP ports for the Microsoft providers, however this script doesn’t examine for them. I’ll attempt to replace it to additionally embrace UDP ports however checking them is harder than checking TCP ports.

Operating the script

The perform Take a look at-MicrosoftEndpoints has a couple of parameters which you should utilize to seek for particular services and products or to specify the placement of the CSV output file:

  • All, scans all providers and the related TCP ports
  • CSVPath, the total path to the CSV file. For instance, d:dataendpointcheck.csv
  • Observe, this parameter adopted by ‘Change’ for instance will seek for all Change ports
  • ServiceDisplayName, this parameter adopted by ‘OneDrive’ will seek for all OneDrive ports
  • URL, this parameter adopted by ‘Outlook’ for instance will seek for all URLs containing Outlook

Observe: For an excellent overview of key phrase to seek for, create an output file utilizing this weblog submit or go to this URL .

On this instance under, I began the script with the -Observe ‘Change’ parameter to check all Change TCP ports. As you’ll be able to see, the script can’t examine the wildcard (*) addresses

The leads to the Out-GridView appear like this, within the IPAddressUsed column you’ll be able to see which IP handle was returned from the DNS question for outlook.workplace.com at that second:

Under is one other instance wherein I used the -Observe ‘Change’ and -CSVPath parameters to avoid wasting the outcomes for Change ports to d:tempoutput.csv.

The CSV file seems to be like this:

The scripts

Under is the script, reserve it to c:dataTest-MicrosoftEndpoints.ps1 for instance. You may run it in your present session by working ‘ . c:dataTest-MicrosoftEndpoints.ps1’ with the intention to have the Take a look at-MicrosoftEndpoints perform obtainable.

perform Take a look at-MicrosoftEndpoints {
    [CmdletBinding(DefaultParameterSetName="Default")]
    param (
        [parameter(parameterSetName = "All")][switch]$All,
        [parameter(Mandatory = $false)][string]$CSVPath,
        [parameter(parameterSetName = "Note")][string]$Observe,
        [parameter(parameterSetName = "ServiceAreaDisplayName")][string]$ServiceAreaDisplayName,
        [parameter(parameterSetName = "URL")][string]$URL
    )

    #Disguise obtain progress, get present JSON url, retrieve all Endpoints and Convert it from JSON format
    $ProgressPreference = "SilentlyContinue"
    strive  where-Object OuterHTML -match 'JSON formatted').href
    
    catch {
        Write-Warning ("Error downloading JSON file, please examine if https://be taught.microsoft.com/en-us/microsoft-365/enterprise/urls-and-ip-address-ranges?view=o365-worldwide is accessible")
        break 
    }

    strive  ConvertFrom-Json
        Write-Host ("Downloading worldwide Microsoft Endpoints") -ForegroundColor Inexperienced
    
    catch {
        Write-Warning ("Error downloading worldwide Microsoft Endpoints, please examine if {0} is accessible" -f $jsonlink)
        break
    }

    #Seek for specified parameter worth
    if ($All)  The place-Object urls -ne $null 

    if ($notice)  The place-Object Notes -Match $notice 

    if ($ServiceAreaDisplayName)  The place-Object ServiceAreaDisplayName -Match $ServiceAreaDisplayName 

    if ($URL)  Choose-Object urls, tcpports, udpports, ips, notes
    

    if ($null -eq $TestEndpoints) {
        Write-Warning ("No outcomes discovered...")
        break
    }

    #Take a look at Microsoft Endpoint Adresses and report if failed or succeeded
    $complete = @() 
    $World:ProgressPreference="SilentlyContinue"
    foreach ($TestEndpoint in $TestEndpoints) {
        if ($TestEndpoint.tcpPorts) {
            foreach ($tcpport in $TestEndpoint.tcpPorts.cut up(',')) {
                foreach ($testurl in $TestEndpoint.urls) {
                    if ($TestEndpoint.notes) {
                        $notes = $TestEndpoint.notes
                    }
                    else {
                        $notes = "No notes obtainable"
                    }

                    #Take a look at connection and retrieve all data
                    $take a look at = Take a look at-NetConnection -Port $tcpport -ComputerName $testurl -ErrorAction SilentlyContinue -InformationLevel Detailed 
                    if ($take a look at.TcpTestSucceeded -eq $true) {
                        $Standing="Succeeded"
                        $ipaddress = $take a look at.RemoteAddress
                        Write-Host ("{0} is reachable on TCP port {1} ({2}) utilizing IP-Handle {3}" -f $testurl, $tcpport, $notes, $ipaddress) -ForegroundColor Inexperienced
                        
                    }
                    else {
                        $Standing = "Failed or could not resolve DNS title"
                        $ipaddress = "Not relevant"
                    }

                    #Set iprange variable if relevant
                    if ($TestEndpoint.ips) {
                        $iprange = $TestEndpoint.ips -join (', ')
                    }
                    else {
                        $iprange = "Not relevant"
                    }
                    
                    $data = [PSCustomObject]@{
                        Standing          = $Standing
                        URL             = $testurl
                        TCPport         = $tcpport
                        IPAddressUsed   = $ipaddress
                        Notes           = $notes
                        EndpointIPrange = $iprange
                    }
                    $complete += $data
                }
            }
        }
    }

    #Output outcomes to Out-Gridview or CSV
    if (-not $CSVPath)  Out-GridView -Title 'Microsoft Endpoints Take a look at outcomes'
    
    else {
        strive {
            New-Merchandise -Path $CSVPath -ItemType File -Drive:$true -ErrorAction Cease | Out-Null
            $Complete | Kind-Object Url, TCPport | Export-Csv -Path $CSVPath -Encoding UTF8 -Delimiter ';' -NoTypeInformation
            Write-Host ("Saved outcomes to {0} `nDone!" -f $CSVPath) -ForegroundColor Inexperienced
        }
        catch {
            Write-Warning ("Couldn't save outcomes to {0}" -f $CSVPath)
        }
    }
}

Obtain the script(s) from GitHub right here

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments