PowerShell Listen Operation

Overview

The PowerShell Listen operation executes a given PowerShell script and notifies the containing operation list about changes whenever it writes to the progress data stream.

Technical Requirements

  • PowerShell needs to be installed on the host machine of the UNIFYNow installation

Usage

This PowerShell Listen operation can be used to complement the PowerShell Changes or any of several other changes operations to improve the timeliness of change notification.

The containing operation list will execute whenever the PowerShell script writes to the progress data stream, which can be done in the following manner:

Write-Progress "<Activity name goes here>";

The activity name will not affect the performance of the operation, but will appear in log messages so it can be convenient to use something meaningful.

Configuration

In addition to the common listen operation configuration settings shared by all Listen Operations, the LDAP Listen operation requires the following by way of configuration:

Name Description
Script The PowerShell script to be executed - see this for more details on implementation of PowerShell scripts.

Image 3549

Examples

The following are a few examples to get started:

Example 1

Changes have occurred whenever a TCP client connects to a particular port

$host = "127.0.0.1";$port = 5252;
$listener = New-Object System.Net.Sockets.TcpListener([System.Net.IPAddress]::Parse($host), $port);
$listener.Start();
while ($true)
{
    $listener.AcceptClient().Close(); # blocking call
    Write-Progress "Progress";
}

Example 2

Changes have occurred whenever a change is made to a particular file

$folder = "C:\Program Files\AddressBook";$file = "entries.txt";
$fsw = New-Object IO.FileSystemWatcher $folder, $file -Property @{NotifyFilter = [IO.NotifyFilters]'LastWrite'};
Register-ObjectEvent $fsw Changed -SourceIdentifier FileChanged -Action { Write-Progress "Progress"; };
# keep script alive so that we can unregister when disabled
try
{
    while ($true) { Start-Sleep 5; }
}
finally
{
    Unregister-Event FileChanged;
}
Operation Listen Operation PowerShell

Is this article helpful for you?