Modules/Reset-SCOMAgentMaintenanceMode.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
<#�
        .SYNOPSIS�
        This�function deletes the maintenance mode registry key.

        .EXAMPLE�
        PS�C:\>�Reset-SCOMAgentMaintenanceMode
#>

Function Reset-SCOMAgentMaintenanceMode
{
    Try
    {
        $RegistryPath = 'HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\MaintenanceMode' 
        $Current = [System.Security.Principal.WindowsIdentity]::GetCurrent()
        $WindowsPrincipal = [System.Security.Principal.WindowsPrincipal]::new($Current)
        If(!($WindowsPrincipal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator )))
        {
            Write-Warning -Message 'Permission denied. Use elevated permission!'
            Throw 
        }
        Else
        {
            If(Test-Path $RegistryPath)
            {
                Remove-Item -Path $RegistryPath -Confirm:$true
            }
            Else
            {
                Write-Warning -Message 'No Maitenance Mode has been set!'
            }
        }
    }
    Catch
    {
        Write-Warning -Message 'Error!'
    }
}