Anudeep,
Welcome to the forum.
I’d use a [PSCustomObject]
instead of a hashtable in such a case. It’s even easier to read and maintain.
param(
[string[]]$computername
)
foreach ($computer in $computername) {
$filebeat_status_before = Get-Service -Name filebeat -ComputerName $computer
Get-Service -Name filebeat -ComputerName $computer | Restart-Service
$filebeat_status_after = Get-Service -Name filebeat -ComputerName $computer
[PSCustomObject]@{
ComputerName = $computer
Status_Before = $filebeat_status_before.Status
Status_After = $filebeat_status_after.Status
}
}