Office Online Server (OOS): how to find WOPI Clients

Submitted by Vladilen on Fri, 02/21/2020 - 13:42

Who support OOS (Office Online Server) in SharePoint on-prem environment...

Scenario:
You have many SharePoint farms and a few OOS farms. You are not sure which SharePoint farm connected to this specific OOS farm. You could check all SharePoint farms... but 
is there a way you can login to OOS server and find - which SharePoint farms are using this OOS farm.

I use  this PowerShell script:

$days = 60 # number of days back you want to parse logs 
$webSites = Get-Website 
$uDomains = @()
foreach($webSite in $webSites) {
    $logDir = "$($Website.logFile.directory)\w3svc$($website.id)".replace("%SystemDrive%",$env:SystemDrive)
    $logFiles = Get-ChildItem $logDir | Sort-Object LastWriteTime | select -Last $days
    foreach($logFile in $logFiles) {
        $uDomains += Get-Content $logfile.FullName           | Select-String -Pattern "WOPIsrc" | %{$_.ToString().Split("&")} | ?{$_.StartsWith("WOPIsrc")} | %{([uri]::UnEscapeDataString($_.Remove(0,8))).split("/")[2]} | select -Unique
    }
}
$uDomains | Sort-Object | select -Unique

I know script is not perfect, e.g. "| select -Last $days" not always true etc...
but still it helps