But the problem remains the same even after storing the get-content result in a variable. I did confirm that it is being treated as an array using the count method.
Still giving me wrong results as seen below :: Piping $ary to the check-backup function is also giving me same output
PS C:\Windows\system32> check-backup -computername $ary
backup was not successful for server: WDCSLVBP01
backup was not successful for server: WDCSLVBP02
backup was not successful for server: WDCBIAP01
backup was not successful for server: WDCBIAP02
backup was not successful for server: WDCBIFP02
backup was not successful for server: WDCBIFP01
backup was not successful for server: WDCDYAP22
backup was not successful for server: WDCIRAP21
Correct result using a the computer name with the parameter :
PS C:\Windows\system32> check-backup -computername wdcirap21
Backup is successful for server:wdcirap21
btw, I see that you set $final variable only if $reply.statusCode -eq “0” …
somewhere around can be logic error
btw, why you do not use Test-Connection ?
I’m insist that you have error with $final
let see example:
you have server1 and server2
server1 is ok and backup succeeded and server2 is offline
what your script do:
check server1 - OK
check backup - OK, set $final=$true
if ($final) write OK
check server2 - ERROR
if ($final) write OK
you see : the final stay $true because you doesnt set it to $false right after foreach !