Modules/Reset-SCOMAgentMaintenanceMode.ps1

<#�
        .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!'
    }
}