我当前的脚本从一个文本文件(服务器名称)读取并从该列表中获取服务。但是,我还想添加一个带有参数的函数,以便它首先使用该参数,如果未指定任何参数,则它将从文本文件中读取。
我当前的代码
[string] $ComputerPath = "E:\Scripts-PowerShell_Command_Others\test
csirt\servernames.otcs.txt"
$ComputerNames = Get-Content -Path $ComputerPath
try {
if ($ComputerNames -ne $null) {
foreach ($c in $ComputerNames) {
$process = Get-Service -ComputerName $c -Name OTCS, otcsadmin, otcsclusteragent, spawner, tomcat7, tomcat8, tomcat8-appworks -ErrorAction SilentlyContinue
Write-Host "Server:" $c -ForegroundColor Yellow
foreach ($p in $process) {
$pd = $p.Name
Write-Output "$($pd)"
}
Write-Host "Processes Running: $($process.Count)" -ForegroundColor Yellow
Write-Output ""
}
}
else {
Write-Output "No computers found in file."
}
} catch {
Write-Host $_ -ForegroundColor Red
}