HOWTO发现在Windows环境中运行的Postgres
那么,我们如何使用PowerShell发现安装在Windows 2012R2/2016环境中的所有Postgres呢?
我写了这个脚本,但我被告知,如果安装不是为了创建服务而编码的,它将找不到所有的postgres实例。。。想法?
#List-PostGres-Servers.ps1
Remove-Item -force "drivepath*-List-PostGres-Servers-log.txt" -ErrorAction
ignore
$today = (Get-Date -Format yyyyMMdd)+"-"+(get-date -uformat %H)
Start-Transcript -Path "drivepath$today-List-PostGres-Servers-log.txt"
$servers = get-content 'drivepathinputlistofservers.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 "drivepathoutputDOMAINNAME-CheckListPostgres.txt" -force -Append
if ($PostGresServicename -eq $null){continue}
else {
$server+","+" "+$PostGresServicename
}
}
}
您可以检查postgres当前是否使用运行
Get-Process *postgres*
在既没有安装服务也没有运行二进制程序的情况下,则不使用postgres安装。或者,在$env:ProgramFiles
或${env:ProgramFiles(x86)}
中搜索psql
。