Powershell用于检查特定url是否由任何浏览器打开

Powershell用于检查特定url是否由任何浏览器打开,powershell,Powershell,我希望脚本检查是否有任何打开的浏览器(检查、firefox、chrome、ie和edge)有一个打开的URL,其中包含什么(例如:)。如果是,它将使用浏览器名称(即:firefox、chrome、edge、ie)并将准确的URL分配给变量 这里可以逐个检查浏览器 if (Get-Process iexplore) { "Internet Explorer is running" } else { "Internet Explorer is not running" } if (Get-Proce

我希望脚本检查是否有任何打开的浏览器(检查、firefox、chrome、ie和edge)有一个打开的URL,其中包含什么(例如:)。如果是,它将使用浏览器名称(即:firefox、chrome、edge、ie)并将准确的URL分配给变量

这里可以逐个检查浏览器

if (Get-Process iexplore) { "Internet Explorer is running" } else { "Internet Explorer is not running" }
if (Get-Process MicrosoftEdge) { "Microsft Edge is running" } else { "Microsft Edge is not running" }
if (Get-Process chrome) { "Google Chrome is running" } else { "Google Chrome is not running" }
if (Get-Process firefox) { "Firefox is running" } else { "Firefox is not running" }

因此,我想检查这4种浏览器中是否有任何一种已打开,如果是,在哪种浏览器上打开了特定网站?

不可能提供准确的URL,但您可以检查哪种浏览器使用的主机:

$server = 'stackoverflow.com'


$connections = Get-NetTCPConnection | Select-Object LocalAddress, LocalPort, @{Label="RemoteHost";Expression={ $h=(Resolve-DNSName $_.RemoteAddress).NameHost; if ($h) {$h} else {$_.RemoteAddress}}}, RemotePort, State, AppliedSetting, OwningProcess |
                ? { $_.RemoteHost -eq $server }

foreach( $connection in $connections ) {

    $process = get-process -Id ($connection.OwningProcess)
    $browser = $process.ProcessName

    "Host $($server) opened by $($browser)"

}

因此,当服务器变量分配给它时,它会向我显示URL,但是浏览器保持为空并且不显示。