-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove-scomrecovery.ps1
More file actions
62 lines (48 loc) · 1.79 KB
/
Copy pathremove-scomrecovery.ps1
File metadata and controls
62 lines (48 loc) · 1.79 KB
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
<#
.Synopsis
Removes selected recoveries
Please use Whatif first. and -Verbose always
.EXAMPLE
.\remove-scomrecovery.ps1 -ManagementServer ms1.contoso.com -ManagementPack "Contoso.ServiceMonitor" -Verbose
VERBOSE: [17.06.2019 15:28:08] Connected to ms1.contoso.com
VERBOSE: Performing the operation "Deleting Recovery Task" on target "TestRecovery1-GateXXX".
VERBOSE: [17.06.2019 15:28:34]Successfully Deleted TestRecovery1-GateXXX
Above example with verbose output
.EXAMPLE
.\remove-scomrecovery.ps1 -ManagementServer ms1.contoso.com -ManagementPack "Contoso.ServiceMonitor" -WhatIf
to simulate Operation please use Whatif.
#>
[CmdLetBinding(
SupportsShouldProcess=$true
)]
Param(
[string]$ManagementServer,
[string]$ManagementPack
)
if (!(Get-SCOMManagementGroupConnection))
{
New-SCOMManagementGroupConnection -ComputerName $ManagementServer
} else {
Write-Verbose "[$(Get-Date -Format G)] Connected to $ManagementServer"
}
$mg=Get-SCOMManagementGroup
$DeleteState = [Microsoft.EnterpriseManagement.Configuration.ManagementPackElementStatus]::PendingDelete
$SelectedRecoveries=Get-SCOMManagementPack -DisplayName $ManagementPack | Get-SCOMRecovery | Out-GridView -PassThru
$SelectedRecoveries | ForEach-Object {
$rec=$mg.Monitoring.GetRecovery.Invoke($_.Id)
$rec.Status = $DeleteState
$mp=$rec.GetManagementPack()
if ($pscmdlet.ShouldProcess($_.Displayname, "Deleting Recovery Task"))
{
try
{
$mp.AcceptChanges()
$Message="[$(Get-Date -Format G)] Successfully Deleted $($_.DisplayName)"
}
catch
{
$Message= "[$(Get-Date -Format G)] Error Occured during save. Error: $($error[0].Exception.Message)"
}
Write-Verbose $Message
}
}