0
很新的PowerShell,只是在這裏玩一些代碼,但遇到了一些我找不到答案。我有一個函數,獲取$ serverList包含服務器名稱和服務名稱,並返回輸出與每個服務的狀態。我在每隔幾秒鐘循環運行一次,但只有函數的第一次運行包含列牧民,之後,我只獲取數據,沒有標題。這裏有什麼交易!寫輸出循環丟失標題
Function ServiceStatus()
{
$objOutput = @()
foreach ($objRecord in $serverList)
{
$obj = New-Object System.Object
$serviceStatus = get-service -ComputerName $objRecord.Server -Name $objRecord.Service
$obj | Add-Member -membertype NoteProperty -name Server -value $objRecord.Server
$obj | Add-Member -membertype NoteProperty -name Service -value $objRecord.Service
$obj | Add-Member -membertype NoteProperty -name Status -value $serviceStatus.status
Write-Output $obj
}
}
For(;;)
{
$currentDate = Get-Date
clear-host
Write-Host Service Checked: $currentDate
ServiceStatus
Start-Sleep -Milliseconds 5000
}