Skip to the main content.

ScriptRunner Blog

Handling Events with PowerShell and .NET (Part 1)

Table of Contents

Post Featured Image

The Oxford dictionary defines an event as “a thing that happens, especially something important”. In the computing world most people associate events with logging, however events go beyond that. In fact, a log is nothing but an output from an event.

This blog post covers two types of events, PowerShell Engine Events and .NET Object Events (click here for part 2 of the series, Handling events with PowerShell and WMI). 

Keep on reading if you want to learn how to handle both PowerShell Engine Events and .NET Object Events and which PowerShell commandlets will get you there.

The Basics: From PowerShell Classes and Objects to Events

Before we delve into the details of PowerShell events, we first need to understand classes and objects.
  • A class is a collection of properties and methods.
  • An object is an instance of the class which is being used to access properties and methods.

Simple, right? Let’s simplify this using a real-world example.

I’m an object of my parents class. My parents have certain properties such as black hair, brown eyes etc. and certain methods such as cooking, dancing etc.

Let’s take a simple example of a class defined in PowerShell:

class PrintName
          
        

Related posts

14 min read

Privacy Management with PowerShell – Let's look at the core features of Priva!

All you need to know about Privacy Management, privacy management policies, rules, and subject rights requests.  

Why...

4 min read

Let's celebrate System Administrator Appreciation Day!

Every last Friday of July, we get to celebrate System Administrator Appreciation Day, a special day dedicated to...

8 min read

PowerShell 7: What are the pros and cons of switching from Windows PowerShell 5.1?

Windows PowerShell 5.1 is usually preinstalled and the default – is it worth switching to PowerShell 7, or will it lead...

About the author: