# Manual Testing section - put stuff here for manually testing script - typically parameters:
#=================================================================================
# $MGName = "SCOM TEST"
# $MSName = "SCOMServer1.domain.com"
#=================================================================================
# Constants section - modify stuff here:
#=================================================================================
# Assign script name variable for use in event logging
$ScriptName = "SCOM.Management.AddManagementGroup.WA.ps1"
$EventID = "1310"
#=================================================================================
# Starting Script section
#=================================================================================
# Gather who the script is running as
$whoami = whoami
#Load the MOMScript API and discovery propertybag
$momapi = New-Object -comObject "Mom.ScriptAPI"
#=================================================================================
# Begin Main Script
#=================================================================================
#Log event that we are starting task
$momapi.LogScriptEvent($ScriptName,$EventID,0, "`nStarting script. `nRunning as ($whoami)")
Write-Host "Task Starting. Running as ($whoami)"
# Check if this is running on a SCOM Management Server or Gateway and stop if it is
$SCOMServerRegKey = "HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Server Management Groups"
IF (Test-Path $SCOMServerRegKey)
{
# This is a management server. STOP
$momapi.LogScriptEvent($ScriptName,$EventID,1,"`nFATAL ERROR: SCOM Server Role Detected. `nThis script should not run on Management Servers or Gateways `n Terminating script.")
Write-Host "`nFATAL ERROR: SCOM Server Role Detected. `nThis script should not run on Management Servers or Gateways `nTerminating script." -ForegroundColor Red
EXIT
}