New-Event - PowerShell


 

Creates a new event. (New-Event)

   

# NAME
New-Event

# SYNOPSIS
Creates a new event.

# SYNTAX
New-Event [-SourceIdentifier] <string> [[-Sender] <psobject>] [[-EventArguments] <PSObject[]>] [[-MessageData] <psobject>] [<CommonParameters>]

# DESCRIPTION
The New-Event cmdlet creates a new custom event.

You can use custom events to notify users about state changes in your program and any change that your program can detect, including hardware or system conditions, application status, disk status, network status, or the completion of a background job.

Custom events are automatically added to the event queue in your session whenever they are raised; you do not need to subscribe to them. However, if you want to forward an event to the local session or specify an action to respond to the event, use the Register-EngineEvent cmdlet to subscribe to the custom event.

When you subscribe to a custom event, the event subscriber is added to your session. If you cancel the event subscription by using the Unregister-Event cmdlet, the event subscriber and custom event are deleted from the session. If you do not subscribe to the custom event, to delete the event, you must change the program conditions or close the Windows PowerShell session.

# PARAMETERS
-EventArguments <PSObject[]>
Specifies an object that contains options for the event.

Required? false
Position? 3
Default value None
Accept pipeline input? false
Accept wildcard characters? false

-MessageData <psobject>
Specifies additional data associated with the event. The value of this parameter appears in the MessageData property of the event object.

Required? false
Position? 4
Default value None
Accept pipeline input? false
Accept wildcard characters? false

-Sender <psobject>
Specifies the object that raises the event. The default is the Windows PowerShell engine.

Required? false
Position? 2
Default value None
Accept pipeline input? false
Accept wildcard characters? false

-SourceIdentifier <string>
Specifies a name for the new event. This parameter is required, and it must be unique in the session.

The value of this parameter appears in the SourceIdentifier property of the events.

Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false

<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".

# INPUTS
None
You cannot pipe input to this cmdlet.

# OUTPUTS
System.Management.Automation.PSEventArgs

# NOTES

The new custom event, the event subscription, and the event queue exist only in the current session. If you close the current session, the event queue is discarded and the event subscription is canceled.

# EXAMPLE 1

C:\PS>new-event -sourceidentifier Timer -sender windows.timer -messagedata "Test"

# Description
-----------
This command creates a new event in the Windows PowerShell event queue. It uses a Windows.Timer object to send the event.

# EXAMPLE 2

C:\PS>function Enable-ProcessCreationEvent
{
$query = New-Object System.Management.WqlEventQuery "__InstanceCreationEvent", (New-Object TimeSpan 0,0,1), "TargetInstance isa 'Win32_Process'"
$processWatcher = New-Object System.Management.ManagementEventWatcher $query
$identifier = "WMI.ProcessCreated"

Register-ObjectEvent $processWatcher "EventArrived" -SupportEvent $identifier -Action {
[void] (New-Event -sourceID "PowerShell.ProcessCreated" -Sender $args[0] -EventArguments $args[1].SourceEventArgs.NewEvent.TargetInstance)
}
}

# Description
-----------
This sample function uses the New-Event cmdlet to raise an event in response to another event. The command uses the Register-ObjectEvent cmdlet to subscribe to the Windows Management Instrumentation (WMI) event that is raised when a new process is created. The command uses the Action parameter of the cmdlet to call the New-Event cmdlet, which creates the new event.

Because the events that New-Event raises are automatically added to the Windows PowerShell event queue, you do not need to register for that event.

RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=135234
Register-ObjectEvent
Register-EngineEvent
Register-WmiEvent
Unregister-Event
Get-Event
Remove-Event
Wait-Event

C:\Windows>powershell get-help Add-Member -full

ColorConsole [Version 1.7.1000] PowerShell 2.0-Export
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2014 Microsoft Corporation.

OS: Windows 10, 8.1, 8, 7, Vista / Windows Server 2016, 2012, 2008
»»»» ColorConsole








Windows-10





Windows-10

... facebook.de
... Windows-10 FAQ
... Windows-10 Info


Become a Sponsor
... Your button here?





PowerShell: Creates a new event.

HTTP: ... PS_Windows/en/New-Event.htm
0.218
7958

Automatisches Anpassen der Energieoptionen unter Windows!

 /

How do I remove the reboot deletion program from my windows 10?

 /

View and delete partitions on Windows 8.1 / 10, can I?

 /

Can I use the Windows XP Explorer.exe in Win-7?

 /

System administrator Windows 10, how to activate the full admin account?

 /

The Windows key combination to start the task manager quickly and directly!

 /

Windows 10 Home oder Pro version?

 /

Reset standard fonts for programs to default in Windows 7, can I?

 /

Problems with Windows-10 and favorites and desktop shortcuts!

 /

Turn off and enable SmartScreen via CMD BATCH command?

 /

Being able to turn off auto-arrange within directorys?

 /

Show hidden files and directorys in Windows 10, can I?

 /