# Getting System Up time in Customized display
#Using this Script you can get the uptime of multiple servers
#save the servers list in notepad with out spaces.it will use to save the time if you want query the uptime of bulk servers.Please contact me for for any sugesstions and feedback
function get-uptime {
param(
$computername =$env:computername
)
$os = Get-WmiObject win32_operatingsystem -ComputerName $computername -ea silentlycontinue
if($os){
$lastbootuptime =$os.ConvertTodateTime($os.LastBootUpTime)
$LocalDateTime =$os.ConvertTodateTime($os.LocalDateTime)
$up =$LocalDateTime - $lastbootuptime
$uptime ="$($up.Days) days, $($up.Hours)h, $($up.Minutes)mins"
$results =new-object psobject
$results |Add-Member noteproperty LastBootUptime $LastBootuptime
$results |Add-Member noteproperty ComputerName $computername
$results |Add-Member noteproperty uptime $uptime
#Display the results
$results | Select-Object computername,LastBootuptime,Uptime
}
else
{
$results =New-Object psobject
$results =new-object psobject
$results |Add-Member noteproperty LastBootUptime "Na"
$results |Add-Member noteproperty ComputerName $computername
$results |Add-Member noteproperty uptime "Na"
#display the results
$results | Select-Object computername,LastBootUptime,Uptime
}
}
$infouptime =@()
foreach($allserver in $allservers){
$infouptime += get-uptime $allserver
}
$infouptime
###############################################
#Getting Computers source
$servers =Get-Content C:\servers.txt
foreach ($server in $servers)
{
get-uptime -computername $server
}
#Using this Script you can get the uptime of multiple servers
#save the servers list in notepad with out spaces.it will use to save the time if you want query the uptime of bulk servers.Please contact me for for any sugesstions and feedback
function get-uptime {
param(
$computername =$env:computername
)
$os = Get-WmiObject win32_operatingsystem -ComputerName $computername -ea silentlycontinue
if($os){
$lastbootuptime =$os.ConvertTodateTime($os.LastBootUpTime)
$LocalDateTime =$os.ConvertTodateTime($os.LocalDateTime)
$up =$LocalDateTime - $lastbootuptime
$uptime ="$($up.Days) days, $($up.Hours)h, $($up.Minutes)mins"
$results =new-object psobject
$results |Add-Member noteproperty LastBootUptime $LastBootuptime
$results |Add-Member noteproperty ComputerName $computername
$results |Add-Member noteproperty uptime $uptime
#Display the results
$results | Select-Object computername,LastBootuptime,Uptime
}
else
{
$results =New-Object psobject
$results =new-object psobject
$results |Add-Member noteproperty LastBootUptime "Na"
$results |Add-Member noteproperty ComputerName $computername
$results |Add-Member noteproperty uptime "Na"
#display the results
$results | Select-Object computername,LastBootUptime,Uptime
}
}
$infouptime =@()
foreach($allserver in $allservers){
$infouptime += get-uptime $allserver
}
$infouptime
###############################################
#Getting Computers source
$servers =Get-Content C:\servers.txt
foreach ($server in $servers)
{
get-uptime -computername $server
}
No comments:
Post a Comment