Operations Manager Shell Data source module.

Microsoft.LS.2015.OperationManagementShell.DS (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.LS.2015.PowerShell.PropertyBag.DS Default

Source Code:

<DataSourceModuleType ID="Microsoft.LS.2015.OperationManagementShell.DS" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ScriptSnippet" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="Microsoft.LS.2015.PowerShell.PropertyBag.DS">
<ScriptName>OperationManagementShell.ps1</ScriptName>
<ScriptBody><Script>
param ([String] $ScriptSnippet)
#############################################################################
# 1. Add operation Manager Snapin.
# 2. Start Operation Manager Console.
# 3. Execute Script Snippet.
# This snippet should add values to the property bag.
# It can use all functions that Operation Management Shell provides.
# 5. Return Property Bag.
#############################################################################

#CONSTANTS###################################################################
$LOG_REG_KEY = "HKLM:\Software\Microsoft\Real-Time Communications\Health"
$OPSMGMT_LOG_KEY = "HKLM:\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\Microsoft.EnterpriseManagement.OperationsManager.Client"
$EVENT_ERROR = 1
$EVENT_WARNING = 2
$EVENT_INFORMATION = 4
$EVENT_ID = 228
$EVENT_SCRIPT_NAME = "OperationManagementShell.ps1"
#############################################################################

#LOGS &amp; EXCEPTIONS###########################################################
$logMessage = ""
$OCS_MODULE_ADDED = "`nSkypeForBusiness Module Added`n";

$PROPERTY_VALUE = "Value of {0} is {1}`n"
$NO_NULL = "parameter {0} can not be null valued."

$EXCEPTION_MESSAGE = "An exception occurred during execution of [{0}], Exception : {1}`n"
#############################################################################

#Helper Functions############################################################
$Script:logMessage = ""
function TRACE ($message)
{
$Script:logMessage += $message + "`n"
}

function ConvertTo-ScriptBlock([string]$string)
{
$scriptblock = $executioncontext.invokecommand.NewScriptBlock($string)
return $scriptblock
}

#############################################################################

$MOMapi = New-Object -comObject "MOM.ScriptApi"
$currentUser = whoami
TRACE ("Running as " + $currentUser + "`n")
TRACE ("`n")
TRACE ("--------------------------------------------------------------------------------`n")
TRACE ("- Skype for Business Server 2015 MP RMS Execution Report -`n")
TRACE ("--------------------------------------------------------------------------------`n")
$ErrorActionPreference = "Stop"
# Flag for tracking whether any exception occurred.
$exceptionOccurred = $false;

try
{
$CommandShellPath = $null
if (test-path $OPSMGMT_LOG_KEY)
{
$CommandShellPath = (get-item $OPSMGMT_LOG_KEY).GetValue("ApplicationBase")
if(!$CommandShellPath)
{
throw "Can not read operation manager installation path. Verify that entry {0}\ApplicationBase is not empty." -f $OPSMGMT_LOG_KEY
}
}
else
{
throw "Can not read operation manager installation path. Verify that path {0} exists." -f $OPSMGMT_LOG_KEY
}
TRACE ($PROPERTY_VALUE -f "CommandShell Path", $CommandShellPath)

if(!$ScriptSnippet) { throw $NO_NULL -f "ScriptSnippet" }
TRACE ($PROPERTY_VALUE -f "Script Snippet", $ScriptSnippet)

$loadedSnapin= get-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorAction SilentlyContinue
if ($loadedSnapin -eq $null)
{
Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorAction SilentlyContinue;
TRACE ("Microsoft.EnterpriseManagement.OperationsManager.Client is loaded.")
}
else
{
TRACE ("Microsoft.EnterpriseManagement.OperationsManager.Client is already loaded.")
}

cd "$CommandShellPath"
.\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Startup.ps1
$Script:bag = $MOMapi.CreatePropertyBag()

TRACE ("Execution Started for [{0}]" -f $ScriptSnippet)
# Sample value for $ScriptSnippet:
# "$objects = @(get-monitoringClass -name $ClassName | get-monitoringObject);$Script:bag.AddValue("Count", $objects.Count);"
$scriptBlock = ConvertTo-ScriptBlock ([string]$ScriptSnippet)
&amp; $scriptBlock
TRACE ("Execution Finished for [{0}]" -f $ScriptSnippet)
TRACE ("Property Bag Values: {0} " -f (out-string -InputObject $bag))
$Script:bag
}
catch
{
TRACE ($EXCEPTION_MESSAGE -f $ScriptSnippet, $_.Exception.ToString())
$exceptionOccurred = $true;
}

if($exceptionOccurred)
{
$MOMapi.LogScriptEvent($EVENT_SCRIPT_NAME, $EVENT_ID, $EVENT_ERROR, $Script:logMessage)
}
else
{
if (test-path $LOG_REG_KEY)
{
$logFlag = (Get-ItemProperty $LOG_REG_KEY).LogOpsMgr

if($logFlag -eq 1)
{
$MOMapi.LogScriptEvent($EVENT_SCRIPT_NAME, $EVENT_ID, $EVENT_INFORMATION , $Script:logMessage)
}
}
}
</Script></ScriptBody>
<SnapIns/>
<Parameters>
<Parameter>
<Name>ScriptSnippet</Name>
<Value>$Config/ScriptSnippet$</Value>
</Parameter>
</Parameters>
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>