#LOGS & EXCEPTIONS###########################################################
$PROPERTY_VALUE = "Value of {0} is {1}."
$NO_NULL = "Error: {0} can not be null."
$DISCOVERY_SUCCESS = "{0} discovery completed for {1}."
$DISCOVERY_EXCEPTION_MESSAGE = "An exception occurred during discovery script, Exception : {0}."
$MESSAGE_LENGTH_HIT_LIMIT = "MESSAGE TRUNCATED DUE TO SIZE LIMIT. Max Limit is [{0}]."
function GetDiscoveryData()
{
$Script:SCOMDiscoveryData
}
# Unfortunately, foreach loop is iterating over $null values. Thank you, Powershell!!!
# In other words;
# foreach {$x in $null} {"test"} => Is printing "test" one time.
# to prevent this we need to use below format.
# foreach (... in strip-null (..)) {}
# E.g foreach {$x in strip-null($null)} {"test"} => Does not print "test".
# http://www.techtalkz.com/microsoft-windows-powershell/165444-foreach-null-interates-block.html
function strip-null($obj)
{
if ($obj -ne $null) { $obj }
}
#############################################################################
#SCRIPT INFO#################################################################
$currentUser = whoami
# Check the execution policy of scripts and see if it is what is expected for our scripts to run if not
# set it to RemoteSigned which is the least supported execution policy this is a fix for RTMA-1762.
$supportedExecutionPolicies="RemoteSigned","Unrestricted","Bypass"
$executionPolicy = get-executionpolicy
if(!($supportedExecutionPolicies -contains $executionPolicy))
{
set-executionpolicy RemoteSigned
$executionPolicy = get-executionpolicy
}
# We need to safeguard ourself against the message limit. The documented message limit is 32786 bytes (~32K).
# http://msdn.microsoft.com/en-us/library/aa363679(VS.85).aspx
# however, when we use mom api to log event it adds some characters to the messages.
# Thus, we restrict the message limit here to 30720(30K).
# if the message is greater than this, we simply truncate it and update the log message.
$maxLimit = 30720
if($logMessage.Length -gt $maxLimit)
{
TRACE ($MESSAGE_LENGTH_HIT_LIMIT -f $maxLimit)
$MOMapi.LogScriptEvent($EVENT_SCRIPT_NAME, $EVENT_ID, $EVENT_SEVERITY , $logMessage.ToString().Substring(0, $maxLimit))
}
else
{
$MOMapi.LogScriptEvent($EVENT_SCRIPT_NAME, $EVENT_ID, $EVENT_SEVERITY , $logMessage.ToString())
} </Script></Contents>
</File>
</Files>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>