Functions/Remove-ExPerfWiz.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Function Remove-ExPerfwiz {
    <#
 
    .SYNOPSIS
    Removes data collector sets from perfmon
 
    .DESCRIPTION
    Used to remove data collector sets from perfmon.
 
    .PARAMETER Name
    Name of the Perfmon Collector set
 
    Default Exchange_Perfwiz
 
    .PARAMETER Server
    Name of the server to remove the collector set from
 
    Default LocalHost
 
    .OUTPUTS
    Logs all activity into $env:LOCALAPPDATA\ExPefwiz.log file
 
    .EXAMPLE
    Remove a collector set on the local machine
 
    Remove-ExPerfwiz -Name "My Collector Set"
 
    .EXAMPLE
    Remove a collect set on another server
 
    Remove-ExPerfwiz -Server RemoteServer-01
 
 
    #>

    [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
    param (

        [Parameter(ValueFromPipelineByPropertyName)]    
        [string]
        $Name = "Exchange_Perfwiz",

        [string]
        $Server = $env:ComputerName
    )

    Process {

        Write-Logfile -string ("Removing Experfwiz for: " + $server)

        # Remove the experfwiz counter set
        if ($PSCmdlet.ShouldProcess("$Server\$Name", "Removing Performance Monitor Data Collector")) {
            [string]$logman = logman delete -name $Name -s $server
        }

        # Check if we have an error and throw and error if needed.
        If ([string]::isnullorempty(($logman | select-string "Error:"))) {
            Write-Logfile "ExPerfwiz removed"
        }
        else {
            Write-Logfile "[ERROR] - Unable to remove Collector"
            Write-Logfile $logman
            Throw $logman
        }
    }

}