23 August,2020 by Tom Collins
If you want a Powershell script to quickly check if Puppet has initiated a reboot on a Windows server , use this script . It uses the Powershell cmdlet -Get-WinEvent.
Typically - a Puppet maintenance window is set per server. If a reboot is required , due to a pending patching change - than the reboot will occur during the designated window. A server owner may experience an unexpected outage - and will want to investigate the root cause. Part of the root cause may include analysing the Event viewer logs for clues.
The Windows Event Logs stores loads of messages, so finding messages related to a Puppet initiated reboot can be a challenge. Executing this code will filter on the System log and the event id 1074, with an string in the Message .
Get-WinEvent -ComputerName $computername -FilterHashtable @{logname='system';id=1074;}|?{$_.message -match "Puppet is rebooting"}
If you want to enhance this script and create a script , which you can execute from the powershell command line .
param ( [Parameter(Mandatory=$true)] [string]$computername ) Get-WinEvent -ComputerName $computername -FilterHashtable @{logname='system';id=1074;}|?{$_.message -match "Puppet is rebooting"}
You would execute the command line as:
PS C:\myscriptlibrary > .\myscriptname.ps1
Read more on powershell
Powershell Script – How to get windows logs events with Get-WinEvent for a date range
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |