# ------------------------------------------------------------------------------------------
# Function to convert Management Pack version and formatted for 3 digits.
# ------------------------------------------------------------------------------------------
function VerToString
{
param($version)
$myver = "Not Installed"
if($version -eq "0")
{
return $myver
}
$verLength = ([string]$version).Length
if($verLength -le 3)
{
return ([string]$version).Substring(0,3)
}
if($verLength -ge 5)
{
return ([string]$version).Substring(0,5)
}
}
# ------------------------------------------------------------------------------------------
# Function to Round-off
# ------------------------------------------------------------------------------------------
function Round( $value, [MidpointRounding]$mode = 'AwayFromZero' ) { [Math]::Round( $value, $mode ) }
# ------------------------------------------------------------------------------------------
# Function to get Server Version
# ------------------------------------------------------------------------------------------
function GetServerVersion()
{
param($KeyToFind)
$MPLocRegKeyPath = "HKLM:\software\Dell\Dell Server Management Pack Suites";
$mpLoc = $null;
$mpLoc = Get-ItemProperty -path:$MPLocRegKeyPath -name:$KeyToFind -ErrorAction:SilentlyContinue;
return $mpLoc;
}
# ------------------------------------------------------------------------------------------
# Function to get Equallogic Suite Version
# ------------------------------------------------------------------------------------------
function GetEqualLogicVersion()
{
param($KeyToFind)
$MPLocRegKeyPath = "HKLM:\SOFTWARE\Dell\Dell EqualLogic Storage Management Pack Suite";
$mpLoc = $null;
$mpLoc = Get-ItemProperty -path:$MPLocRegKeyPath -name:$KeyToFind -ErrorAction:SilentlyContinue;
return $mpLoc;
}
# --------------------------------------------------------------------------------------
# Function to get the registry keys (Path and LicenseWebServerURL) from Windows registry
# --------------------------------------------------------------------------------------
function GetMPLocationFromRegistry()
{
param($KeyToFind)
$MPLocRegKeyPath = "HKLM:\software\Dell\Dell Server Management Pack Suites";
$mpLoc = $null;
$mpLoc = Get-ItemProperty -path:$MPLocRegKeyPath -name:$KeyToFind -ErrorAction:SilentlyContinue;
return $mpLoc;
}
# --------------------------------------------------------------------------------------------------------------------
# Function to instantiate Management Feature instances if they are detected, else create Scalable Feature instances
# Dell.FeatureManagement.MonitoringFeature - base class of any feature, one instance will always be created
# Specialized MonFeature instance will be created based on presence (install) of the corresponding feature
# This is useful for displaying only applicable tasks on a feature (installed feature)
# ---------------------------------------------------------------------------------------------------------------------
function CreateMP
{
param($Discovery, $name, $desc, $avail, $version, $config, $license)
# ----------------------------------------------------------------------
# Function to invoke primary discoover wrt SCOM objects and environment
# ----------------------------------------------------------------------
function CallPrimaryDiscoveryScript
{
param ($Discovery, $SCOMEnv)
$visitor = @{}
# Initialize an array of MPNames as null for each
foreach ($mp in $DeviceMonitoringMPs.Keys)
{
$visitor += @{ $mp = $null }
}
# Initialize an array of FeatureVisitor, Map and Version as default value for each (displayed if not otherwise set)
$featurevisitor = @{}
$featuremap = @{}
$featurever = @{}
# gets all SCOM management packs which fit criteria of listing in $DeviceMonitoringMPs ARRAY and if present in that list, VisitorMap[MP] is set to value
$SCOMEnv.GetManagementPacks() | where-object { $DeviceMonitoringMPs.Contains($_.Name) } | foreach -process {
$visitor[$_.Name] = $_
}
#----------------------------------------------------------------------------
# Function to invoke create Equal MP wrt SCOM objects and environment
#----------------------------------------------------------------------------
function CreateEqlMP
{
param($Discovery, $name, $desc, $avail, $version, $config, $license)
#----------------------------------------------------------------------------
# Function to invoke Equal primary discovery wrt SCOM objects and environment
#----------------------------------------------------------------------------
function CallEqlPrimaryDiscoveryScript
{
param ($Discovery, $SCOMEnv)
$visitor = @{}
# Initialize an array of MPNames as null for each
foreach ($mp in $DeviceMonitoringMPs.Keys)
{
$visitor += @{ $mp = $null }
}
# Initialize an array of FeatureVisitor, Map and Version as default value for each (displayed if not otherwise set)
$featurevisitor = @{}
$featuremap = @{}
$featurever = @{}
# gets all SCOM management packs which fit criteria of listing in $DeviceMonitoringMPs ARRAY and if present in that list, VisitorMap[MP] is set to value
$SCOMEnv.GetManagementPacks() | where-object { $DeviceMonitoringMPs.Contains($_.Name) } | foreach -process {
$visitor[$_.Name] = $_
}
function GetConnection()
{
psDebugLog -level 1 -message $this.state
$MachineRegErrorMsg = "Can not find Operations Manager Management Server name for the local machine.";
$UserRegKeyPath = "HKCU:\software\Microsoft\Microsoft Operations Manager\3.0\User Settings";
$MachineRegKeyPath = "HKLM:\software\Microsoft\Microsoft Operations Manager\3.0\Machine Settings";
$UserRegValueName = "SDKServiceMachine";
$MachineRegValueName = "DefaultSDKServiceMachine";
$ConnectingMsg = "Connecting to Operations Manager Management Server '{0}'.";
$ConnectErrorMsg = "Can not connect to Operations Manager Management Server '{0}'.";
$AccessDeniedErrorMsg = "Access is denied to Operations Manager Management Server '{0}'.";
$regKey = $null;
$regValue = $null;
# Set the initial server value to the MS argument.
# If the argument is empty the normal registry lookup sequence will kickin.
# If the argument is not empty the user will be connected to the specified connection.
$server = $null;
# Get the User Operations Manager Product Registry Key
if ($server -eq $null -or $server.Length -eq 0)
{
$regValue = Get-ItemProperty -path:$UserRegKeyPath -name:$UserRegValueName -ErrorAction:SilentlyContinue;
if ($regValue -ne $null)
{
$server = $regValue.SDKServiceMachine;
}
}
if ($server -eq $null -or $server.Length -eq 0)
{
# Get the Machine Operations Manager Product Registry Key if the user setting could not be found.
$regValue = Get-ItemProperty -path:$MachineRegKeyPath -name:$MachineRegValueName -ErrorAction:SilentlyContinue;
if ($regValue -ne $null)
{
$server = $regValue.DefaultSDKServiceMachine;
}
}
# If the default Operations Manager Management Server name can not be found in the registry then default to 'localhost'.
if ($server -eq $null -or $server.Length -eq 0)
{
psDebugLog -level 1 -message ($MachineRegErrorMsg)
$server = "localhost";
}
# Create a connection and make it the current location.
if ($server -ne $null -and $server.Length -gt 0)
{
# Format the connecting message.
$msg = $ConnectingMsg -f $server;
psDebugLog -level 1 -message ($msg)
# If the connection failed due to insufficient access then prompt for credentials.
if ($error.Count -gt 0 -and $error[0].Exception -is [Microsoft.EnterpriseManagement.Common.UnauthorizedAccessMonitoringException])
{
psDebugLog -level 1 -message ("Failed to connect")
$error.Clear();
}
function Write-Info
{
param ([string] $msg)
#Write-Host $msg
}
function psDebugLog
{
param($level, $message)
if (($level -gt 0) -and ($level -le $logLevel))
{
$currentTime = Get-Date -f "yyyy-MM-dd_HH.mm.ss"
Out-File -FilePath $this.loglocation -InputObject ($currentTime + " :: " + $message) -Append
}
}
function GetConnection()
{
psDebugLog -level 1 -message $this.state
$managementServerName = ""
$persistConnection = $false
$interactive = $false
$MachineRegErrorMsg = "Can not find Operations Manager Management Server name for the local machine.";
$UserRegKeyPath = "HKCU:\software\Microsoft\Microsoft Operations Manager\3.0\User Settings";
$MachineRegKeyPath = "HKLM:\software\Microsoft\Microsoft Operations Manager\3.0\Machine Settings";
$UserRegValueName = "SDKServiceMachine";
$MachineRegValueName = "DefaultSDKServiceMachine";
$ConnectingMsg = "Connecting to Operations Manager Management Server '{0}'.";
$ConnectErrorMsg = "Can not connect to Operations Manager Management Server '{0}'.";
$AccessDeniedErrorMsg = "Access is denied to Operations Manager Management Server '{0}'.";
$ConnectPromptMsg = "Enter the name of the Operations Manager Management Server to connect to.";
$ConnectPrompt = "Management Server";
$serviceNotRunningErrorMsg = "The Data Access service is either not running or not yet initialized. Check the event log for more information.";
$HostNotFoundErrorMsg = "No such host is known";
$regKey = $null;
$regValue = $null;
# Set the initial server value to the MS argument.
# If the argument is empty the normal registry lookup sequence will kickin.
# If the argument is not empty the user will be connected to the specified connection.
$server = $managementServerName;
$drive = $null;
# Get the User Operations Manager Product Registry Key
if ($server -eq $null -or $server.Length -eq 0)
{
$regValue = Get-ItemProperty -path:$UserRegKeyPath -name:$UserRegValueName -ErrorAction:SilentlyContinue;
if ($regValue -ne $null)
{
$server = $regValue.SDKServiceMachine;
}
}
if ($server -eq $null -or $server.Length -eq 0)
{
# Get the Machine Operations Manager Product Registry Key if the user setting could not be found.
$regValue = Get-ItemProperty -path:$MachineRegKeyPath -name:$MachineRegValueName -ErrorAction:SilentlyContinue;
if ($regValue -ne $null)
{
$server = $regValue.DefaultSDKServiceMachine;
}
}
# If the default Operations Manager Management Server name can not be found in the registry then default to 'localhost'.
if ($server -eq $null -or $server.Length -eq 0)
{
psDebugLog -level 1 -message $MachineRegErrorMsg
$server = "localhost";
}
# Create a connection and make it the current location.
$this.connection = $null;
if ($server -ne $null -and $server.Length -gt 0)
{
# Format the connecting message.
$msg = $ConnectingMsg -f $server;
psDebugLog -level 1 -message $msg
# Create the new connection.
$this.connection = New-SCOMManagementGroupConnection -ComputerName: $server -PassThru -ErrorAction:Stop
}
$this.state = 'connected'
return $this.connection
}
#Special case where un-installation of EQL making Monitoring Feature instance remaining because Triggered Discovery is not running so to make triggered discovery run
#we are creating a EQL FMP object
$ServerRegistryKeyEntry = GetServerVersion -KeyToFind "CurrentVersion"
$EqualLogicRegistryKeyEntry = GetEqualLogicVersion -KeyToFind "CurrentVersion"
if($ServerRegistryKeyEntry -ne $null -and $EqualLogicRegistryKeyEntry -eq $null )
{
psDebugLog -level 1 -message ("Found Server Registry present and EqualLogic Registry not present")
$Instance = $Discovery.CreateClassInstance("$MPElement[Name='Dell.FeatureManagement.EqualLogic.SelectedHostMgmtServer']$")
$Instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $localFqdn)
$Instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Dell Feature Monitoring Host Emulator")
$Instance.AddProperty("$MPElement[Name='Dell.FeatureManagement.DMSInstallBase']/FMPEqualLogic$", "Not Selected")
$Instance.AddProperty("$MPElement[Name='Dell.FeatureManagement.DMSInstallBase']/SuiteEqualLogic$", "Not Installed")
$Discovery.AddInstance($Instance)
}
if($ServerRegistryKeyEntry -ne $null -and $FMPType -eq "SuiteServer")
{
#Found a Dell Management Pack Suite installation
if ($FMPHostFqdn -eq $localFqdn)
{
psDebugLog -level 1 -message ("FMPHostFqdn is equal to localFqdn, Current Management Server is selected as FMP Host ")
if ($FMPType -eq "SuiteServer")
{
psDebugLog -level 1 -message ("Dell Server Management Pack Suite installed on MS.")
$Instance = $Discovery.CreateClassInstance("$MPElement[Name='Dell.FeatureManagement.SelectedHostMgmtServer']$")
$Instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $localFqdn)
$Instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Dell Feature Monitoring Host Emulator")
$Instance.AddProperty("$MPElement[Name='Dell.FeatureManagement.DMSInstallBase']/FMPServer$", "Not Selected")
$Discovery.AddInstance($Instance)
psDebugLog -level 1 -message ("Discovered instance of selected Dell Management Suite Host Emulator - " + $localFqdn + " , added to SCOM")
CallPrimaryDiscoveryScript -Discovery $Discovery -SCOMEnv $scomenv
}
}
else
#FQDN not same as override
{
psDebugLog -level 1 -message ("FMPHostFQDN is not equal to the Local FQDN , so current management server is not selected as FMP Host ")
$Instance = $Discovery.CreateClassInstance("$MPElement[Name='Dell.FMPDiscovery.Sink']$")
$Instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Dell Discovery Sink")
$Instance.AddProperty("$MPElement[Name='Dell.FMPDiscovery.Sink']/Name$","Dummy Object")
$Discovery.AddInstance($Instance)
}
}
elseif($EqualLogicRegistryKeyEntry -ne $null -and $FMPType -eq "SuiteEqualLogic" )
{
#Found a Dell EqualLogic Management Pack Suite installation
if ($FMPHostFqdn -eq $localFqdn)
{
psDebugLog -level 1 -message ("FMPHostFqdn is equal to localFqdn, Current Management Server is selected as FMP Host ")
psDebugLog -level 1 -message ("Dell Equal Management Pack Suite installed on MS.")
$Instance = $Discovery.CreateClassInstance("$MPElement[Name='Dell.FeatureManagement.SelectedHostMgmtServer']$")
$Instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $localFqdn)
$Instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Dell Feature Monitoring Host Emulator")
$Instance.AddProperty("$MPElement[Name='Dell.FeatureManagement.DMSInstallBase']/FMPServer$", "Not Selected")
$Discovery.AddInstance($Instance)
psDebugLog -level 1 -message ("Populating the EqualLogic Monitoring Feature Instances")
CallEqlPrimaryDiscoveryScript -Discovery $Discovery -SCOMEnv $scomenv
}
else
#FQDN not same as override
{
psDebugLog -level 1 -message ("FMPHostFQDN is not equal to the Local FQDN , so current management server is not selected as FMP Host ")
$Instance = $Discovery.CreateClassInstance("$MPElement[Name='Dell.FMPDiscovery.Sink']$")
$Instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Dell Discovery Sink")
$Instance.AddProperty("$MPElement[Name='Dell.FMPDiscovery.Sink']/Name$","Dummy Object")
$Discovery.AddInstance($Instance)
}
}
else
#No registry entries found
{
psDebugLog -level 1 -message ("Dell Management Pack Suites not installed.")
$Instance = $Discovery.CreateClassInstance("$MPElement[Name='Dell.FMPDiscovery.Sink']$")
$Instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Dell Discovery Sink")
$Instance.AddProperty("$MPElement[Name='Dell.FMPDiscovery.Sink']/Name$","Dummy Object")
$Discovery.AddInstance($Instance)
}