ActiveScriptEventConsumer

Active Script Event Consumer

Runs a predefined script in an arbitrary scripting language when an event is delivered to it.

On this page

Main example

List instances

# All instances of ActiveScriptEventConsumer, with the main properties
Get-CimInstance -ClassName ActiveScriptEventConsumer -Namespace 'root/subscription' |
    Select-Object -Property Name, KillTimeout, MachineName, MaximumQueueSize

Examples

Filter with WQL

# WQL filter evaluated by the provider: names starting with "a" (the WQL wildcard is %)
$cimParameters = @{
    ClassName = 'ActiveScriptEventConsumer'
    Namespace = 'root/subscription'
    Filter    = "Name LIKE 'a%'"
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, KillTimeout, MachineName, MaximumQueueSize

The filter is evaluated by the WMI provider: less data is transferred than with Where-Object.

Query a remote computer (CIM session)

review before running
# Name of the remote computer
$computerName = 'SERVER01'
# The CIM session (WSMan by default) can be reused for several queries
$cimSession = New-CimSession -ComputerName $computerName
try {
    $cimParameters = @{
        CimSession = $cimSession
        ClassName  = 'ActiveScriptEventConsumer'
        Namespace  = 'root/subscription'
    }
    Get-CimInstance @cimParameters |
        Select-Object -Property Name, KillTimeout, MachineName, MaximumQueueSize
} finally {
    Remove-CimSession -CimSession $cimSession
}

WSMan (WinRM) is used by default. For a host without WinRM, create the session with -SessionOption (New-CimSessionOption -Protocol Dcom). Add -Credential to use another account.

Show the class structure

# Class structure: properties, types and flags (Key, ReadOnly…)
$cimClass = Get-CimClass -ClassName ActiveScriptEventConsumer -Namespace 'root/subscription'
$cimClass.CimClassProperties |
    Select-Object -Property Name, CimType, Flags

Properties

8 of 8 properties
NameTypeAccessDescription
CreatorSIDuint8[]read

Array that represents the security identifier (SID), which uniquely identifies the creator of the Active Script Event consumer. This property is inherited from __EventConsumer.

Code
# Value of CreatorSID for each instance
# CreatorSID is an array: -ExpandProperty returns its items one by one
$cimParameters = @{
    ClassName = 'ActiveScriptEventConsumer'
    Namespace = 'root/subscription'
    Property  = 'CreatorSID'
}
Get-CimInstance @cimParameters |
    Select-Object -ExpandProperty CreatorSID
KillTimeoutuint32read

Number, in seconds, that the script is allowed to run. If 0 (zero), which is the default, the script is not terminated.

Code
# Value of KillTimeout for each instance
$cimParameters = @{
    ClassName = 'ActiveScriptEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'KillTimeout')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, KillTimeout
MachineNamestringread

Name of the computer to which WMI sends events. By convention of Microsoft standard consumers, the script consumer cannot be run remotely. Third-party consumers can also use this property. This property is inherited from __EventConsumer.

Code
# Value of MachineName for each instance
$cimParameters = @{
    ClassName = 'ActiveScriptEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'MachineName')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, MachineName
MaximumQueueSizeuint32read

Maximum queue, in bytes, for the Active Script Event consumer. This property is inherited from __EventConsumer.

Code
# Value of MaximumQueueSize for each instance
$cimParameters = @{
    ClassName = 'ActiveScriptEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'MaximumQueueSize')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, MaximumQueueSize
Name keystringread/write

Unique identifier for the event consumer. If you rename the consumer, the result is two equal consumers that have different names.

Code
# Value of Name for each instance
$cimParameters = @{
    ClassName = 'ActiveScriptEventConsumer'
    Namespace = 'root/subscription'
    Property  = 'Name'
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name

Warning. Changes the system: check with -WhatIf first. An elevated console is often required.

# Warning: changes Name on the instance. -WhatIf shows the operation without running it.
# Target instance
$instanceParameters = @{
    ClassName = 'ActiveScriptEventConsumer'
    Namespace = 'root/subscription'
    Filter    = "Name = 'Example'"
}
$instance = Get-CimInstance @instanceParameters
$setParameters = @{
    InputObject = $instance
    Property    = @{ Name = 'Example' }
    WhatIf      = $true  # Remove this line to actually apply the change
}
Set-CimInstance @setParameters
ScriptFileNamestringread

Name of the file from which the script text is read, intended as an alternative to specifying the text of the script in the ScriptText property. This property must be NULL if the ScriptText property is not NULL.

Note: When you specify the ScriptFileName, it is important to secure the executable that you are launching. If the executable is not in a secure location or secured with a strong access control list (ACL), anyone can replace the executable with a different one. For more information about ACLs, see Creating a Security Descriptor (SD) for a New Object in C++.

Code
# Value of ScriptFileName for each instance
$cimParameters = @{
    ClassName = 'ActiveScriptEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'ScriptFileName')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, ScriptFileName
ScriptingEnginestringread

Name of the scripting engine to use, for example, "VBScript". This property cannot be NULL.

Code
# Value of ScriptingEngine for each instance
$cimParameters = @{
    ClassName = 'ActiveScriptEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'ScriptingEngine')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, ScriptingEngine
ScriptTextstringread

Text of the script that is expressed in a language known to the scripting engine. This property must be NULL if the ScriptFileName property is not NULL.

Code
# Value of ScriptText for each instance
$cimParameters = @{
    ClassName = 'ActiveScriptEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'ScriptText')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, ScriptText

Remarks

This class is derived from the __EventConsumer abstract class. It is located in the root\subscription namespace.

When the text of a script is specified in the event consumer instance, the script has access to the event instance in the script environment variable TargetEvent.

The scripts run in the LocalSystem security context. As a security measure, only a local system administrator or a domain administrator can configure the scripting consumer. Access rights are not checked until run time. After the consumer is configured, any user can trigger the event that causes the script to .

Failure to load the scripting engine or parse and validate the script is considered a failure. Error return codes from the script and terminating the script by using a time-out are also considered failures.

Either ScriptText or ScriptFileName must be not NULL. If both properties are NULL or not NULL, an error is generated.

When WMI is run as a service, scripts run by ActiveScriptEventConsumer do not generate screen output. Scripts that use MsgBox do run, but they do not display information on the screen. Running the WMI service as an executable file is not supported, but WMI allows scripts that use the MsgBox function to display output or accept user input. None of the methods provided by the WScript) object can be used because ActiveScriptEventConsumer does not use Windows Script Host (WSH).

Inheritance

Superclass chain

  1. __SystemClass
  2. __IndicationRelated
  3. __EventConsumer
  4. ActiveScriptEventConsumer

Known subclasses

No known subclass.

Requirements

Namespace
root/subscription
Minimum client
Windows Vista
Minimum server
Windows Server 2008
MOF file
Scrcons.mof
DLL
Scrcons.exe
Class qualifiers

AMENDMENT

Microsoft source

Source: Microsoft Learn

Descriptions, properties and methods come from the Microsoft documentation (MicrosoftDocs/win32 repository), published under the CC BY 4.0 licence. Formatting and translations are specific to this site; the PowerShell examples are written for it.