I am newbie for powershell. I got a script to check server uptime but I don't know
1) how to output the result?
2) how to change the path of computer.txt==foreach ($computer in Get-Content "computers.txt")?
Function Get-HostUptime {
param ([string]$ComputerName)
$Uptime = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $ComputerName
$LastBootUpTime = $Uptime.ConvertToDateTime($Uptime.LastBootUpTime)
$Time = (Get-Date) - $LastBootUpTime
Return '{0:00} Days, {1:00} Hours, {2:00} Minutes, {3:00} Seconds' -f $Time.Days, $Time.Hours, $Time.Minutes, $Time.Seconds
}
foreach ($computer in Get-Content "computers.txt")
{
$c = Get-WmiObject Win32_PingStatus -f "Address='$computer'"
if($c.StatusCode -eq 0)
{
$sysuptime = Get-HostUptime -ComputerName $computer
write-host "$computer" "$sysuptime"
}
else
{
write-host "$computer is not reachable"
}
}