functions/message/Remove-PSFMessageLevelModifier.ps1

function Remove-PSFMessageLevelModifier
{
    <#
        .SYNOPSIS
            Removes a message level modifier.
         
        .DESCRIPTION
            Removes a message level modifier.
     
            Message Level Modifiers can be created by using New-PSFMessageLevelModifier.
            They are used to emphasize or deemphasize messages, in order to help with debugging.
         
        .PARAMETER Name
            Name of the message level modifier to remove.
         
        .PARAMETER Modifier
            The actual modifier to remove, as returned by Get-PSFMessageLevelModifier.
         
        .PARAMETER EnableException
            This parameters disables user-friendly warnings and enables the throwing of exceptions.
            This is less user friendly, but allows catching exceptions in calling scripts.
         
        .EXAMPLE
            PS C:\> Get-PSFMessageLevelModifier | Remove-PSFMessageLevelModifier
     
            Removes all message level modifiers, restoring everything to their default levels.
     
        .EXAMPLE
            PS C:\> Remove-PSFMessageLevelModifier -Name "mymodule.foo"
     
            Removes the message level modifier named "mymodule.foo"
    #>

    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipeline = $true)]
        [string[]]
        $Name,
        
        [Parameter(ValueFromPipeline = $true)]
        [PSFramework.Message.MessageLevelModifier[]]
        $Modifier,
        
        [switch]
        $EnableException
    )
    
    process
    {
        foreach ($item in $Name)
        {
            if ($item -eq "PSFramework.Message.MessageLevelModifier") { continue }
            
            if ([PSFramework.Message.MessageHost]::MessageLevelModifiers.ContainsKey($item.ToLower()))
            {
                [PSFramework.Message.MessageHost]::MessageLevelModifiers.Remove($item.ToLower())
            }
            else
            {
                Stop-PSFFunction -Message "No message level modifier of name $item found!" -EnableException $EnableException -Category InvalidArgument -Tag 'fail','input','level','message' -Continue
            }
        }
        foreach ($item in $Modifier)
        {
            if ([PSFramework.Message.MessageHost]::MessageLevelModifiers.ContainsKey($item.Name))
            {
                [PSFramework.Message.MessageHost]::MessageLevelModifiers.Remove($item.Name)
            }
            else
            {
                Stop-PSFFunction -Message "No message level modifier of name $($item.Name) found!" -EnableException $EnableException -Category InvalidArgument -Tag 'fail', 'input', 'level', 'message' -Continue
            }
        }
    }
}