Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive

This script will output all virtual directories within Exchange for every Exchange server within the environment. Handy for when you bring new servers into the environment.

   Get-ExchangeVirtualDirectory - Gathers all Exchange virtual directories
   Gathers all Exchange Virtual Directories. Virtual Directories gathered:
    Outlook Anywhere
    .\Get-ExchangeVirtualDirectory -ExportCSV C:\Temp\VirtualDirectories.csv
.PARAMETER VerboseMode
    Outputs results to console
    Path to export CSV to with -NoTypeInformation
    Written by Jeremy Corbello

    * Website:
    * Twitter:
    * LinkedIn:
    * Github:

    Change Log:
    V1.0 - 01/05/2018  - Initial Version
param (

        [string]$ExportCSV = $null

#Add Exchange snapin if not already loaded in the PowerShell session
if (Test-Path $env:ExchangeInstallPath\bin\RemoteExchange.ps1)
    . $env:ExchangeInstallPath\bin\RemoteExchange.ps1
    Connect-ExchangeServer -auto -AllowClobber
    Write-Host "Established Remote Exchange Session"
    Write-Warning "Exchange Server management tools are not installed on this computer."

$servers = Get-ExchangeServer
$data = @()

foreach ($server in $servers) {
    $owa = Get-OwaVirtualDirectory -Server $($ | Select-Object InternalUrl,ExternalUrl
    $ecp = Get-EcpVirtualDirectory -Server $($ | Select-Object InternalUrl,ExternalUrl
    $actSync = Get-ActiveSyncVirtualDirectory -Server $($ | Select-Object InternalUrl,ExternalUrl
    $webServ = Get-WebServicesVirtualDirectory -Server $($ | Select-Object InternalUrl,ExternalUrl
    $oab = Get-OabVirtualDirectory -Server $($ | Select-Object InternalUrl,ExternalUrl
    $mapi = Get-MapiVirtualDirectory -Server $($ | Select-Object InternalUrl,ExternalUrl
    $oAny = Get-OutlookAnywhere -Server $($ | Select-Object ExternalHostname,InternalHostname,ExternalClientsRequireSsl,InternalClientsRequireSsl
    $autoDiscover = Get-ClientAccessServer -Identity $($ | Select-Object AutoDiscoverServiceInternalUri -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
    $obj = New-Object PSObject
    $obj | Add-Member -Type NoteProperty -Name Server -Value ($
    $obj | Add-Member -Type NoteProperty -Name OwaInternalUrl -Value ($owa.InternalUrl)
    $obj | Add-Member -Type NoteProperty -Name OwaExternalUrl -Value ($owa.ExternalUrl)
    $obj | Add-Member -Type NoteProperty -Name EcpInternalUrl -Value ($ecp.InternalUrl)
    $obj | Add-Member -Type NoteProperty -Name EcpExternalUrl -Value ($ecp.ExternalUrl)
    $obj | Add-Member -Type NoteProperty -Name ActiveSyncInternalUrl -Value ($actSync.InternalUrl)
    $obj | Add-Member -Type NoteProperty -Name ActiveSyncExternalUrl -Value ($actSync.ExternalUrl)
    $obj | Add-Member -Type NoteProperty -Name WebServicesInternalUrl -Value ($webServ.InternalUrl)
    $obj | Add-Member -Type NoteProperty -Name WebServicesExternalUrl -Value ($webServ.ExternalUrl)
    $obj | Add-Member -Type NoteProperty -Name OabInternalUrl -Value ($oab.InternalUrl)
    $obj | Add-Member -Type NoteProperty -Name OabExternalUrl -Value ($oab.ExternalUrl)
    $obj | Add-Member -Type NoteProperty -Name MapiInternalUrl -Value ($mapi.InternalUrl)
    $obj | Add-Member -Type NoteProperty -Name MapiExternalUrl -Value ($mapi.ExternalUrl)
    $obj | Add-Member -Type NoteProperty -Name OutlookAnywhereExternalHostname -Value ($oAny.ExternalHostname)
    $obj | Add-Member -Type NoteProperty -Name OutlookAnywhereExternalClientsRequireSsl -Value ($oAny.ExternalClientsRequireSsl)
    $obj | Add-Member -Type NoteProperty -Name OutlookAnywhereInternalHostname -Value ($oAny.InternalHostname)
    $obj | Add-Member -Type NoteProperty -Name OutlookAnywhereInternalClientsRequireSsl -Value ($oAny.InternalClientsRequireSsl)
    $obj | Add-Member -Type NoteProperty -Name AutoDiscoverServiceInternalUri -Value ($autoDiscover.AutoDiscoverServiceInternalUri)
    $data += $obj

if ($VerboseMode) {
    $data | Format-List
if ($ExportCSV -ne $null) {
    $data | Export-Csv -Path $ExportCSV -NoTypeInformation