如何在 Windows 环境中发现 Postgres 运行
HOWTO Discover Postgres Running in Windows Environment
如何在 Windows 环境
中发现 Postgres 运行
那么我们如何使用 PowerShell 发现 Windows 2012R2/2016 环境中安装的所有 Postgres?
我写了这个脚本,但我被告知如果安装没有被编码来创建服务,我将找不到所有的 postgres 实例...想法?
#List-PostGres-Servers.ps1
Remove-Item -force "drive\path\*-List-PostGres-Servers-log.txt" -ErrorAction
ignore
$today = (Get-Date -Format yyyyMMdd)+"-"+(get-date -uformat %H)
Start-Transcript -Path "drive\path$today-List-PostGres-Servers-log.txt"
$servers = get-content 'drive\path\input\listofservers.txt'
foreach ($server in $servers){
if ((Test-Connection -Count 1 -ComputerName $server -quiet) -eq $false){continue}
else{
$PostGresSearch = (get-service -ComputerName $server -name *postgres* -ErrorAction Ignore -WarningAction Ignore -InformationAction Continue)
$PostGresServicename = $PostGresSearch.Name
#|out-file -Encoding ascii "drive\path\output\DOMAINNAME-CheckListPostgres.txt" -force -Append
if ($PostGresServicename -eq $null){continue}
else {
$server+","+" "+$PostGresServicename
}
}
}
您可以查看 postgres 当前是否 运行:
Get-Process *postgres*
如果既没有安装服务也没有安装二进制文件 运行,那么您就没有使用 postgres 安装。或者,在 $env:ProgramFiles
或 ${env:ProgramFiles(x86)}
中搜索 psql
.
如何在 Windows 环境
中发现 Postgres 运行那么我们如何使用 PowerShell 发现 Windows 2012R2/2016 环境中安装的所有 Postgres?
我写了这个脚本,但我被告知如果安装没有被编码来创建服务,我将找不到所有的 postgres 实例...想法?
#List-PostGres-Servers.ps1
Remove-Item -force "drive\path\*-List-PostGres-Servers-log.txt" -ErrorAction
ignore
$today = (Get-Date -Format yyyyMMdd)+"-"+(get-date -uformat %H)
Start-Transcript -Path "drive\path$today-List-PostGres-Servers-log.txt"
$servers = get-content 'drive\path\input\listofservers.txt'
foreach ($server in $servers){
if ((Test-Connection -Count 1 -ComputerName $server -quiet) -eq $false){continue}
else{
$PostGresSearch = (get-service -ComputerName $server -name *postgres* -ErrorAction Ignore -WarningAction Ignore -InformationAction Continue)
$PostGresServicename = $PostGresSearch.Name
#|out-file -Encoding ascii "drive\path\output\DOMAINNAME-CheckListPostgres.txt" -force -Append
if ($PostGresServicename -eq $null){continue}
else {
$server+","+" "+$PostGresServicename
}
}
}
您可以查看 postgres 当前是否 运行:
Get-Process *postgres*
如果既没有安装服务也没有安装二进制文件 运行,那么您就没有使用 postgres 安装。或者,在 $env:ProgramFiles
或 ${env:ProgramFiles(x86)}
中搜索 psql
.