Cmdlets/Clear-SqlMessage.ps1

<#
.Synopsis
    Clears all available informational messages.
 
.Description
    Clear-SqlMessage removes all informational messages generated by
    Invoke-SqlScalar, Invoke-SqlQuery, or Invoke-SqlUpdate. Not all providers
    support informational messages.
 
.Parameter ConnectionName
    User defined name for connection.
 
#>

Function Clear-SqlMessage {
    [cmdletBinding()]
    Param([Parameter(Position=0)][ValidateNotNullOrEmpty()][Alias("cn")][string]$ConnectionName = "default")

    If(TestConnectionName -ConnectionName $ConnectionName) {
        Try { $Script:Connections.$ConnectionName.ClearMessages() }
        Catch [System.NotSupportedException] {
            Write-Warning ("[{0}] {1}" -f $Script:Connections.$ConnectionName.ProviderType(), $_.exception.message)
        }
    }
}

Export-ModuleMember -Function Clear-SqlMessage