Category Archives: PowerShell

PowerTip: Get the Last Boot Time with PowerShell | Scripting Blog

PowerTip: Get the Last Boot Time with PowerShell

Summary: Learn how to get the last boot time for your computer.

Hey, Scripting Guy! Question How can I find the last boot time for my computer by using Windows PowerShell?

Hey, Scripting Guy! Answer In Windows PowerShell 3.0, use the Get-CimInstance cmdlet, and select the LastBootUptime property from the Win32_Operatingsystem WMI class:

PS C:\> Get-CimInstance -ClassName win32_operatingsystem | select csname, lastbootuptime

csname                                     lastbootuptime

——                                     ————–

EDLT                                       3/22/2013 11:27:01 AM

Hey, Scripting Guy! Answer In Windows PowerShell 2.0 and Windows PowerShell 1.0, use the Get-WmiObject cmdlet, and then translate the returned date to a readable format:

PS C:\> Get-WmiObject win32_operatingsystem | select csname, @{LABEL=’LastBootUpTime’

;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}

csname                                     LastBootUpTime

——                                     ————–

EDLT                                       3/22/2013 11:27:01 AM

Source: PowerTip: Get the Last Boot Time with PowerShell | Scripting Blog

Deep scriptblock logging: Record PowerShell commands in the event log

As a powerful tool, PowerShell is not only of interest for admins but also for hackers. To detect suspicious activities, it is helpful to have all executed commands recorded. In addition to recording the history in a text file, PowerShell has also supported logging in the event log since version 5.

Source: Deep scriptblock logging: Record PowerShell commands in the event log