我需要在一些服务器上安装Zabbix代理,大约有一千个。在每台服务器(Windows 2008和2012)中,我想检查是否使用了端口10050,如果是,那么我需要知道谁正在使用它的哪个进程,如果是Zabbix,我会停止它。像这样:将输出插入变量
$id = Get-NetTCPConnection -LocalAddress 0.0.0.0 -LocalPort 10050 -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty OwningProcess;
if (-not $id) {
Write-Host "$zabbix Port Opened"
if (Get-WmiObject -Class win32_service -Filter "Name='Zabbix Agent'") {
Write-host "Already exists. Deleting..."
$servZabbix = (Get-WmiObject -Class win32_service -Filter "Name='Zabbix Agent'")
$servZabbix.Delete()
我的挑战是在Windows 2008服务器上使用PowerShell v2(我猜)。 我想做一个适用于任何Windows Server版本的通用PowerShell脚本。 你们可以帮我吗?
哪部分与Powershell v2不兼容? –
您可以执行“Invoke-Command -Computername -Scriptblock {$ PSVersionTable.psversion}”以获取Powershell版本。 –
@MaximeFranchot'Get-NetTCPConnection'不是POSH2。您可以在2.0版本模式下打开PowerShell:'powershell.exe -Version 2.0',并进行测试,如果你想... – VertigoRay