Helpers/Resolve-SCOMWorkflowName.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

function Resolve-SCOMWorkflowName
{
    [CmdletBinding()]
    [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingCmdletAliases', '')]
    param
    (
        [Parameter(Mandatory = $true, Position = 0)]
        [System.String]
        $Name,

        [Parameter(Mandatory = $true, Position = 1)]
        [Microsoft.SystemCenter.Core.Connection.Connection]
        $Connection
    )

    if ($null -ne ($Rule = Get-SCOMRule -Name $Name))
    {
        Write-Output $Rule
    }
    elseif ($null -ne ($Monitor = Get-SCOMMonitor -Name $Name))
    {
        Write-Output $Monitor
    }
    elseif ($null -ne ($Discovery = Get-SCOMDiscovery -Name $Name))
    {
        Write-Output $Discovery
    }
    else
    {
        $Exception   = New-Object -TypeName 'System.Exception' -ArgumentList ('Workflow name {0} not found as rule, monitor or discovery!' -f $Name)
        $ErrorRecord = New-Object -TypeName 'System.Management.Automation.ErrorRecord' -ArgumentList $Exception, '0', 'ObjectNotFound', $Name

        $PSCmdlet.ThrowTerminatingError($ErrorRecord)
    }
}