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
}
# Form Aqua SLED object
Function FormAquaSled
{
PARAM([string]$ServiceTag,[string]$hostMgmtServer,$ARYServer)
$arryServer=@($ARYServer)
# Create health service instance for the proxy computer. This will be used as the source in the relationship to ensure that agent on proxy agent manages the discovered instances.
$healthServiceInstance = $discoveryData.CreateClassInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthService']$" )
$healthServiceInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$",$hostMgmtServer)
$discoveryData.AddInstance($healthServiceInstance)
$instance = $discoveryData.CreateClassInstance("$MPElement[Name='DellModelServer!Dell.Server.FMServer']$")
psDebugLog -level 1 -message ("Aqua Sled Object ID: " + "$MPElement[Name='DellModelServer!Dell.Server.FMServer']$")
psDebugLog -level 1 -message ("HostMgmtServer Object : " + $hostMgmtServer)
$instance.AddProperty("$MPElement[Name='DellModelServer!Dell.Server.FMServer']/ServiceTag$",$ServiceTag)
$instance.AddProperty("$MPElement[Name='DellModelServer!Dell.Server.FMServer']/HostManagementServer$",$hostMgmtServer)
$sledName="Dell FM Server: "+$ServiceTag
psDebugLog -level 1 -message ("Dell FM Server name : " + $sledName)
$instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$",$sledName)
$discoveryData.AddInstance($instance)
# Create an instance of the HealthServiceShouldManageEntity class. This ensures that the target instance (the discovered network device) is managed on the agent of the source (the proxy computer).
$healthServiceRelationship = $discoveryData.CreateRelationshipInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthServiceShouldManageEntity']$")
$healthServiceRelationship.Source = $healthServiceInstance
$healthServiceRelationship.Target = $instance
$discoveryData.AddInstance($healthServiceRelationship)