Hi guys, please someone help with the simple few lines below
Getting the error shown
else : The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program.
_______________________________________________________
$Computers = Get-Content C:\scripts\ComputerName.txt
$Computers | ForEach-Object {
if (Test-Connection $_ -Count 1 -Quiet)
{Write-Host "$_ is online"}
if (Test-WSMan -ComputerName $_.Name -ErrorAction SilentlyContinue) {
Write-Host "$($_.Name) - WinRM Enabled" }
else { Write-host "$($_.Name) - WinRM Disabled "}
else {
Write-Host "$_ is offline"
}
}