Public/Remove-SwNodeApplicationInsight.ps1

Function Remove-SwNodeApplicationInsight {
    <#
        .SYNOPSIS
        Remove Application insight from specific node.
 
        .DESCRIPTION
        This function can remove some application insight from selected node.
        Right now these application are supported:
            1- Exchange
            2- IIS
            3- ScheduleTasks
            4- SQL
 
        Note: Node Id of target machine is required, you can execute "Get-Node" command to find node Id.
    #>

    [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='High')]
    Param (
        [Parameter(Mandatory = $true)]
        [SolarWinds.InformationService.Contract2.InfoServiceProxy]$InfoServiceProxy,

        [Parameter(Mandatory = $true)]
        [int]$NodeId,

        [Parameter(Mandatory = $true)]
        [ValidateSet('Exchange', 'IIS', 'ScheduledTasks', 'SQL')]
        [string]$Type
    )

    Begin{
        $id = $NodeId.ToString()
    }
    Process{
        $name = Get-SwNode -InfoServiceProxy $InfoServiceProxy -Id $NodeId
        $applications = Get-SwisData -SwisConnection $InfoServiceProxy -Query `
                                        "select id from orion.apm.Application where `
                                        nodeid = '$id' and name like '%$Type%'"

        foreach($app in $applications){
            if($PSCmdlet.ShouldProcess( "Verbose Description !", "Remove Resource " + "Caption")){
                Invoke-SwisVerb -SwisConnection $InfoServiceProxy -EntityName "Orion.APM.Application" -Verb "DeleteApplication" -Arguments @($app)
                Write-Verbose -Message "Application $Type is removed from $name"
            }

        }
    }
    End{
    }
}