Hi,
So i'm trying to write this small script to get the status of a process on a list of servers using Get-Process.
So when i run the below code i dont get the results as expected. It doesnt check for the process on all servers and gives the same result as the first server on the list. i think i'm missing something in the if loop but cant seem to figure it out. i think its
if loop because when i run the code as "Get-process chrome -computername Server1, Server2 | format-table Name, MachineName -auto | Out-File "$File " -append"" then i get the info needed but as it doesnt give proper formatted info so
trying to write a script which gives little info on what servers the process is running and which one it isnt using if statement.
So can someone please guide me on where i'm missing on the code i've so far.
Thanks.
Set-ExecutionPolicy Unrestricted Clear host $SCRIPT_PARENT = Split-Path -Parent $MyInvocation.MyCommand.Definition $date = ( Get-Date ).ToString('yyyyMMdd') #$File = ($SCRIPT_PARENT + "\log-$date.txt") $Servers = "Server1", "Server2" Clear-Content $File Write-Host "Please wait... Collecting information... " -foregroundcolor "black" -backgroundcolor "yellow" $Check = Get-Process -name chrome -EA SilentlyContinue $Servers | ForEach-Object { $Server = $_ If ($Check -eq $null) { { Write-Host "$Server = Doesnt exist" } Else { Write-Host "$Server = Process exist" } } #more coding to do more stuff