-
Notifications
You must be signed in to change notification settings - Fork 0
/
Disable-SCOMCollection.ps1
68 lines (53 loc) · 2.53 KB
/
Disable-SCOMCollection.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
67
<#
.Synopsis
Disables Performance or Event Collection Events
.DESCRIPTION
Disables Performance or Event Collection Events
.EXAMPLE
Get-SCOMManagementPack | where {$_.Name -match 'SQL.+2014\.Monitoring'}| .\Disable-SCOMCollection.ps1 -ManagementServer test -OverrideMP "Test MP" -DisableTarget PerformanceCollection -WhatIf
What if: Performing the operation "Disabling PerformanceCollection Rule in (Test MP)" on target "MSSQL 2014: DB File Allocated Free Space (MB)".
What if: Performing the operation "Disabling PerformanceCollection Rule in (Test MP)" on target "MSSQL 2014: Parallel GC work item/sec".
What if: Performing the operation "Disabling PerformanceCollection Rule in (Test MP)" on target "MSSQL 2014: Used amount of memory in the resource pool (KB)"
#>
[CmdletBinding(SupportsShouldProcess=$true,
ConfirmImpact='Medium')]
Param
(
# ManagementPacks to be disabled
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true,ValueFromPipeline=$true)]
$SourceMP,
# Param2 help description
[Parameter(Mandatory=$true)]
[string]$OverrideMP,
# ManagementServer to be selected
[Parameter(Mandatory=$true)]
[string]$ManagementServer,
#DisableTarget
[Parameter(Mandatory=$true)]
[ValidateSet("EventCollection","PerformanceCollection")]
[string]$DisableTarget
)
Begin
{
Import-Module OperationsManager -Verbose:$false
if ((Get-SCOMManagementGroupConnection|where {$_.IsActive}).ManagementServerName -notmatch "$ManagementServer") {
New-SCOMManagementGroupConnection -ComputerName $ManagementServer
Write-Verbose "Connected to management server: $($ManagementServer)"
} else {
Write-Verbose "Already connected to $((Get-SCOMManagementGroupConnection|where {$_.IsActive}).ManagementServerName)"
if (!(Get-SCOMManagementPack -DisplayName $OverrideMP)) {
Throw "OverrideMP not found. Please create it before the script"
}
}
}
Process
{
$Rules=$_ | Get-SCOMRule | where {$_.Category -eq $DisableTarget}
foreach ($Rule in $Rules) {
if ($pscmdlet.ShouldProcess($Rule.DisplayName, "Disabling $($DisableTarget) Rule in ($OverrideMP)"))
{
#Disable-SCOMRule -Rule $PerfRules -ManagementPack $overridesmp
Disable-SCOMRule -Rule $Rule -ManagementPack $overridesmp | Out-Null
}
}
}