Get-DSCTrigger.ps1
function Get-DSCTrigger { <# .Synopsis Gets DSC triggers .Description Gets WMI event subscriptions that will trigger a DSC resource .Link Register-DSCTrigger .Link Unregister-DSCTrigger .Example Get-DSCTrigger #> [OutputType([PSObject])] param( # The name of a remote computer [Parameter(ValueFromPipelineByPropertyName=$true)] [string] $ComputerName, # The credential used to connect to the remote computer [Parameter(ValueFromPipelineByPropertyName=$true)] [PSCredential] $Credential ) process { #region Find Appropriate Subscriptions in WMI and Convert them to Property Bags Get-WmiObject @psBoundParameters -Namespace root\Subscription -Class CommandLineEventConsumer -Filter "Name LIKE '%_DSCConsumer'" | ForEach-Object { $subscription = $_ $eventFilter = $_.GetRelated() $ConfigName = ($subscription.CommandLineTemplate -split "\\")[-1] -ireplace '\.ps1', '' $props = @{ Filter = $eventFilter.Query Namespace = $eventFilter.EventNamespace ConfigurationName = $ConfigName Name = $subscription.Name.Replace('_DSCConsumer', '') } if ($ComputerName) { $props.ComputerName = $subscription.__Server } New-Object PSObject -Property $props } #endregion Find Appropriate Subscriptions in WMI and Convert them to Property Bags } } |