Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Wait-Event cmdlet.
What can I do with it?
Pause a running script or session and wait for an event to occur before continuing.
Example:
The built-in PowerShell help has a great example for New-Event. It uses New-Event to create a custom event based on a reaction to another event. Use Wait-Event to make the current session pause until a new process has been opened.
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Get-Event cmdlet.
What can I do with it?
Retrieve events from the event queue.
Example:
The built-in PowerShell help has a great example for New-Event. It uses New-Event to create a custom event based on a reaction to another event. Once the event has been created Get-Event can be used to examine details of that event and any others currently in the queue.
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the New-Event cmdlet.
What can I do with it?
Create a custom event.
Example:
The built-in PowerShell help has a great example for New-Event. It uses New-Event to create a custom event based on a reaction to another event.
function Enable-ProcessCreationEvent { $query = New-Object System.Management.WqlEventQuery “__InstanceCreationEvent”, (New-Object TimeSpan 0,0,1), “TargetInstance isa ‘Win32_Process’” $processWatcher = New-Object System.
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Register-EngineEvent cmdlet.
What can I do with it?
Subscribe to events generated by the PowerShell engine or the New-Event cmdlet.
Example:
Subscribe to an event when the PowerShell session exits, and save information including the date and time out to a log file.
Register-EngineEvent PowerShell.Exiting -Action {“PowerShell exited at " + (Get-Date) | Out-File c:\log.
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Get-EventSubscriber cmdlet.
What can I do with it?
Retrieve event subscribers from the current session.
Example:
Use the Register-ObjectEvent cmdlet to register for an event to check for new processes, use the ManagementEventWatcher .NET object to form the basis of the object to monitor and save information including the date and time out to a log file.
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Register-ObjectEvent cmdlet.
What can I do with it?
Subscribe to an event on a local or remote computer generated by a .NET Framework object and carry out actions based on the event.
Example:
Register for an event to check for new processes, use the ManagementEventWatcher .NET object to form the basis of the object to monitor and save information including the date and time out to a log file.
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Register-WMIEvent cmdlet.
What can I do with it?
Subscribe to a WMI event on a local or remote computer and carry out actions based on the event.
Example:
Register for a WMI which checks every 10 seconds for any new processes which have started, call it Check for New Processes and save information including the date and time out to a log file.
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Set-WmiInstance cmdlet.
What can I do with it?
Set an instance of a WMI class.
Example:
Change the value of MaxLogFileSize within the Win32_WMISetting class from the default of 6556 to 13112.
Set-WmiInstance -Class Win32_WMISetting -Argument @{MaxLogFileSize=13112}
You will notice that the MaxLogFileSize value is updated:
How could I have done this in PowerShell 1.
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Remove-WMIObject cmdlet.
What can I do with it?
Remove an instance of a WMI class.
Example:
Start Windows Calcultor. Retrieve the running process and terminate it.
calc Get-WmiObject Win32_Process -Filter “name=‘calc.exe’” | Remove-WmiObject
How could I have done this in PowerShell 1.0?
In the above example you could have called the Terminate method on the object returned in the WMI query.
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Invoke-WMIMethod cmdlet.
What can I do with it?
Call WMI Methods.
Example:
Retrieve the WMI instances of the Print Spooler service. Pipe it through to Invoke-WMIMethod and call the StopService method.
Get-WmiObject Win32_Service -filter “name=‘spooler’” | Invoke-WmiMethod -Name StopService
Notice the service State changes.
How could I have done this in PowerShell 1.0?