Prashanth Jayaram



Function Get-Uptime

{

param

(

[Parameter(Position=0,Mandatory=$true)]

[alias("cn")]

[string[]]$ComputerName ="LocalComputer"

)

$Object =@()

foreach ($Computer in $ComputerName)

{

if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {

$Uptime = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer

$LastBootUpTime = $Uptime.ConvertToDateTime($Uptime.LastBootUpTime)

$Time = (Get-Date) - $LastBootUpTime

$Object += New-Object PSObject -Property @{

ComputerName = $Computer.ToUpper();

Uptime = '{0:00} Days, {1:00} Hours, {2:00} Minutes, {3:00} Seconds' -f $Time.Days, $Time.Hours, $Time.Minutes, $Time.Seconds;}

}

}

$column1 = @{expression="ComputerName"; width=15; label="ComputerName"; alignment="left"}

$column2 = @{expression="Uptime"; width=45; label="Uptime"; alignment="left"}

# with Customized formatting

$Object|format-table $column1, $column2

#Without formatting

$Object|Format-Table -AutoSize

#Grid output

$Object.GetEnumerator() | Out-GridView -Title " UpTime Details"

}

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download

To fulfill the demand for quickly locating and searching documents.

It is intelligent file search solution for home and business.

Literature Lottery

Related searches