Hi,
I am a newb when it comes to scripting/powershell. I have a PS script to read from a list of server names in a txt file and return the last boot time information for each server. The script works great except I would like to get that information exported into a csv file so I can import it into excel and be able to sort it. The Main thing that I want to display is just the server name and the last boot date. my script is as follows...
$Servers = Get-Content “ServersTest.txt”foreach($Server in $Servers)
{
#CREATE A WMI QUERY AGAINST THE CURRENT $SERVER NAME
$wmi=Get-WmiObject -class Win32_OperatingSystem -computer $Server
#THE LAST BOOT TIME COMES BACK IN A LONG FORMAT SO CONVERT IT TO A VALID DATE TIME AND ASSIGN IT TO $LASTBOOTTIME
$lastBootUpTime=$wmi.ConvertToDateTime($wmi.LastBootUpTime)
#CALCULATE TIME SINCE LAST BOOT
$now = Get-Date
$upTime = $now - $lastBootUpTime
$days = $Uptime.Days
$hours = $Uptime.Hours
$min = $uptime.Minutes
$sec = $uptime.Seconds
#DISPLAY RESULTS
Write-Host "SERVER NAME:" $Server "Last Boot Time:" $lastBootUpTime
Write-Host "HAS BEEN UP FOR: " $days "DAYS " $hours "HOURS " $min "MINUTES" $sec "SECONDS"
}
Any Help would be greatly appreciated.
Thank you,
Kevin