PowerShell Logo Small

New-Event



This is the built-in help made by Microsoft for the command 'New-Event', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Creates a new event.

SYNTAX


New-Event [-SourceIdentifier] <String> [[-Sender] [<PSObject>]] [[-EventArguments] [<PSObject[]>]] [[-MessageData] [<PSObject>]] [-InformationAction {SilentlyContinue | Stop
| Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String[]>]] [<CommonParameters>]



Search powershellhelp.space

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.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=293992
Get-Event
Register-EngineEvent
Register-ObjectEvent
Register-WmiEvent
Remove-Event
Unregister-Event
Wait-Event

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

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



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










-------------------------- EXAMPLE 2 --------------------------

PS C:\>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)
}
}



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.