Windows PowerShell


PowerShell Scripting with get-Eventlog

Introduction to Scripting Eventlog on a Remote Machine

Challenge, to interrogate logs on a remote machine.

PowerShell Eventlog Topics

 ♣

Example 1: Eventlog with System.Diagnostics PowerShell EventLog

Instructions:

Pre-requisite: Visit Microsoft's site and download the correct version of PowerShell for your operating system.

Here are instructions for executing the PowerShell code from the command line.

  • Launch Windows PowerShell
  • Copy all the lines of code into memory
    (For instance, from the Example below)
  • Right-click on the PowerShell symbolPowerShell Scripts How to Copy and Paste
  • Edit --> Paste
  • Check the menus on screenshot to the right
  • Press 'Enter' to execute the pasted code

# PowerShell script to list the eventlogs on another computer
$Log = "Application"
$Computer ="LocalHost"
$ID = "1002"

$Objlog = New-Object system.diagnostics.eventLog($Log, $Computer)
$Objlog.get_entries() |
Where-object { $_.eventID -eq $id }

Learning Points

Note 1:  New-Object creates an instance of system.diagnostics.  In particular an eventLog instance

Note 2:  I have used variables to control the output, $Log, $Computer and $ID.

Important: Please amend $Computer = "LocalHost" to the name of the remote computer.

More work

Introduce an $array and a loop to interrogate a batch of computers.

Guy Recommends: SolarWinds LANSurveyorSolarwinds LANSurveyor

LANSurveyor will produce a neat diagram of your network topology.  But that's just the start; LANSurveyor can create an inventory of the hardware and software of your machines and network devices.  Other neat features include dynamic update for when you add new devices to your network.  I also love the ability to export the diagrams to Microsoft Visio.

Finally, Guy bets that if you take a free trial of LANSurveyor then you will find a device on your network that you had forgotten about, or someone else installed without you realizing!

Download a Free Trial of LANSurveyor

Summary of Eventlog

.

See more PowerShell examples for event logs

PowerShell Home   • EventVwr -list   • EventVwr errors   • Eventlog   • Diagnostics

Getting started  • Error examples

Please write in if you see errors of any kind.  Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Google

Web  This website

Review of Orion NPMGuy Recommends: Orion's NPM - Network Performance Monitor

Orion's performance monitor is designed for detecting network outages. A network-centric view make it easy to see what's working, and what needs your attention.

This utility guides you through troubleshooting by indicating whether the root cause is faulty equipment or resource overload.

Download a free trial of the Network Performance Monitor

 

Home Copyright © 1999-2009 Computer Performance LTD All rights reserved

Please report a broken link, or an error.