Table of Contents Single Server Reboot Report:Multiple Servers Reboot Report: Single Server Reboot Report: 01. Get
-
WinEvent
FilterHashtable @{logname
=
'System'
; id
1074
} |
02.
ForEach
Object {
03.
04.
$rv
New
Object PSObject | Select
Object Date, User, Action, Process, Reason, ReasonCode, Comment
05.
$rv.Date
$_.TimeCreated
06.
$rv.User
$_.Properties[
6
].Value
07.
$rv.Process
0
08.
$rv.Action
4
09.
$rv.Reason
2
10.
$rv.ReasonCode
3
11.
$rv.Comment
5
12.
13.
14.
} | Select
Object Date, Action, Reason, User
01.
Function
Get
-ComInfo {
param(
## Computers
$computers
)
"#"
*160
"Server Reboot Report"
"Generated $(get-date)"
"Generated from $(gc env:computername)"
15.
-WinEvent -ComputerName $computers -FilterHashtable @{logname=
'System'; id=1074} |
16.
ForEach-
Object
{
17.
18.
$rv =
PSObject |
Select
Date
, User, Action, Process, Reason, ReasonCode, Comment
19.
$rv.
= $_.TimeCreated
20.
$rv.User = $_.Properties[6].Value
21.
$rv.Process = $_.Properties[0].Value
22.
$rv.Action = $_.Properties[4].Value
23.
$rv.Reason = $_.Properties[2].Value
24.
$rv.ReasonCode = $_.Properties[3].Value
25.
$rv.Comment = $_.Properties[5].Value
26.
27.
28.
, Action, Reason, User
29.
30.
}
31.
32.
-Content computers.txt | ForEach-
-ComInfo -computers $_}
*80
"Server LastBootUpTime-InstallDate-Sl Nos Report"
-CimInstance Win32_OperatingSystem -comp $computers | select csname,LastBootUpTime
-ComInfo -computers $_} |
Out-File -Append Servers_LastBootUpTime.txt
Richard Mueller edited Revision 15. Comment: Removed tag "w2k8r2", added tags "Has TOC" and "Has Comment"
Maheshkumar S Tiwari edited Revision 12. Comment: Added tags and minor edit
Balaji M Kundalam edited Revision 11. Comment: Typography - minor correction
Pinged back from www.vinithmenon.com/.../powershell-script-to-find-who-restarted.html
(shutdown events tracker)
wmic /output:C:\reboot.htm ntevent where (LogFile='system' and SourceName='user32') get Message, TimeGenerated /format:hform.xsl
1. How to find the particular process details
Get-Process -Name lsass
2. Determine a year is LeapYear or not?
[datetime]::isleapyear(2008)
3. How to count days?
$result = [datetime] "06/16/2014" - [DateTime]::Now
$result.TotalDays
4. How to take the output from a varriable.
PS C:\> $name = "Biswajit Biswas"
PS C:\> Write-Output $name
Biswajit Biswas
5.List the Properties and Methods of a WMI Class.
Get-WmiObject -List -Namespace 'root\CIMV2'
Get-EventLog -ComputerName <computer_name> System | Where-Object { $_.Source -eq 'user32' } | ConvertTo-HTML | Out-File C:\Reboot.htm