Last active
April 27, 2017 00:48
-
-
Save LeeSartorelli/636d9cc7eff6c7f351a4b1c3ef3c23e5 to your computer and use it in GitHub Desktop.
This function gets the last boot up time of one or more computers from WMI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-LastReboot{ | |
<# | |
.SYNOPSIS | |
Get last reboot time. | |
.DESCRIPTION | |
This function gets the last boot up time of a computer from WMI. It can accept both pipeline input and parameter input. | |
.PARAMETER $ComputerName | |
Required. Name of the Computer to return data for. | |
.EXAMPLE | |
Get-LastReboot -ComputerName localhost | |
Retrieve last reboot time for a single computer | |
.EXAMPLE | |
Get-LastReboot -ComputerName localhost,dc | |
Retrieve last reboot time for multiple computers | |
.EXAMPLE | |
Get-Content .\Servers.txt | Get-LastReboot | |
Retrieve last reboot time for multiple computers, using pipeline input | |
.NOTES | |
Author: Lee Sartorelli | |
Created: 4/4/2017 | |
ForEach loop is required to support comma separated values as a parameter input. | |
#> | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory, | |
ValueFromPipeline)] | |
[Alias('Display Name','Server','host''CN')] | |
[string[]]$ComputerName | |
) | |
Begin {} | |
Process | |
{ | |
ForEach($Computer in $ComputerName) | |
{ | |
$LastBoot = (Get-WMIObject Win32_OperatingSystem -ComputerName $Computer).LastBootUpTime | |
$LastBoot = [Management.ManagementDateTimeConverter]::ToDateTime($LastBoot) | |
Write-Output "$Computer was last rebooted $LastBoot" | |
} | |
} | |
End {} | |
} #Function Get-LastReboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment