尝试创建Powershell脚本以查找未在计算机列表(文本文件)上运行的进程。我找到了下面的脚本,但我不确定如何使用get-content cmdlet。
$ProcessName = "VPDICOMServer"
if((get-process $ProcessName -ErrorAction SilentlyContinue) -eq $Null)
echo "Process is not running" }else{ echo "Process is running" }
答案 0 :(得分:0)
假设您的computers.txt
文件是新行分隔的计算机名称列表,您可以使用foreach
循环:
$ProcessName = 'VPDICOMServer'
$Path = "$Env:UserProfile\Documents\computers.txt"
foreach ($Computer in (Get-Content -Path $Path)) {
然后你可以对每一个执行Get-Process
(假设你有权限):
if (Get-Process -ComputerName $Computer -Name $ProcessName -ErrorAction 'SilentlyContinue') {
'Process is running'
} else {
'Process is not running'
}
}