I'm trying to restart a list of computers from a text file. To test if the computer is up first. This seems simple, but just can't get it to work.
I can't see where I'm going wrong
$comp = Get-Content C:\temp\srv.txt
$s = Get-Credential
foreach ($comps in $comp)
{
{
if(-not(Test-Connection -ComputerName $comp -Count 1 ))
{
Write-Host "$comp unavailable"
}
}
else
{
Restart-Computer -ComputerName $comp -force -Credential $s
}
}
Thanks for your help in advance :)
You were close, you just had a couple extra brackets in the code which were not needed.