CheckAgentProxyEnabledDS (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
SchedulerDS DataSource System.Scheduler Default
CheckAgentProxyProbe ProbeAction Microsoft.SystemCenter.VirtualMachineManager.2012.PowerShellProbeActionModuleType Default

Overrideable Parameters:

IDParameterTypeSelector
FrequencyInHoursint$Config/FrequencyInHours$

Source Code:

<DataSourceModuleType ID="CheckAgentProxyEnabledDS" Accessibility="Public">
<Configuration>
<xsd:element name="FrequencyInHours" type="xsd:integer"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="FrequencyInHours" Selector="$Config/FrequencyInHours$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<!-- Scheduler to fire at certain frequency -->
<DataSource ID="SchedulerDS" TypeID="System!System.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval Unit="Hours">$Config/FrequencyInHours$</Interval>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<!-- Probe Action that checks if Agent Proxying is enabled -->
<ProbeAction ID="CheckAgentProxyProbe" TypeID="Microsoft.SystemCenter.VirtualMachineManager.2012.PowerShellProbeActionModuleType">
<ScriptBody><Script>
function CheckAgentProxy([string]$omServer, [string]$vmmServer)
{
$error.Clear();

# Load OpsMgr snap-inn
add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";
if ($error.Count -ne 0)
{
#ignore error if snap-in is already loaded
$error.Clear();
}

# Connect to OpsMgr - change management server to your RMS
new-managementGroupConnection -ConnectionString:$omServer;
set-location "OperationsManagerMonitoring::";

if ($error.Count -ne 0)
{
$errMsg = "Unable to connect to OpsMgrserver: " + $error;
$evt.WriteEntry($errMsg, $infoevent, 25932);
return $false;
}


#VMM server might be installed on one of the Management servers
foreach ($managementServer in Get-ManagementServer)
{
if ($managementServer.Name.Equals($vmmServer))
{
return $managementServer.ProxyingEnabled.Value;
}
}

#VMM server on a non-Management server
foreach ($agent in Get-Agent)
{
if ($agent.Name.Equals($vmmServer))
{
return $agent.ProxyingEnabled.Value;
}
}

#default is to return false
return $false;
}


function GetVMMCreds()
{
$domain = "$RunAs[Name="PROV2Library!Microsoft.SystemCenter.VirtualMachineManager.2012.VMMServerConnectionRunAsProfile"]/Domain$";
$username = "$RunAs[Name="PROV2Library!Microsoft.SystemCenter.VirtualMachineManager.2012.VMMServerConnectionRunAsProfile"]/UserName$";
$pass = "$RunAs[Name="PROV2Library!Microsoft.SystemCenter.VirtualMachineManager.2012.VMMServerConnectionRunAsProfile"]/Password$";


$cred = $null;
if ($domain -AND $username -AND $pass)
{
#Append domain to get domain\username
$domainUser = $domain + "\" + $username;

#Create Cred object
$securePass = ConvertTo-SecureString -AsPlainText $pass -force
$cred = New-Object System.Management.Automation.PSCredential $domainUser, $securePass;
}

return $cred
}

$error.Clear();
$oAPI = New-Object -comObject 'MOM.ScriptAPI'
$pBag = $oAPI.CreatePropertyBag()

$evt = New-Object System.Diagnostics.Eventlog("Application");
$evt.Source = "Microsoft.SystemCenter.VirtualMachineManager.2012.Monitoring.AgentProxyEnabled";
$infoevent = [System.Diagnostics.EventLogEntryType]::Error;

$cred = GetVMMCreds

if ($cred -ne $null)
{
$module = get-module -name "virtualmachinemanagercore"
if ($module -eq $null)
{
$modulePath = get-itemproperty -path "HKLM:\Software\Microsoft\Microsoft System Center Virtual Machine Manager Administrator Console\Setup";
Import-Module ($modulePath.InstallPath + "bin\psModules\virtualmachinemanagercore\virtualmachinemanagercore.psd1");
}

$VMMServer = Get-SCVMMServer "localhost" -Credential $cred;

if ($error.Count -ne 0)
{
$evt.WriteEntry($error, $infoevent, 25931);
Remove-Module -Name virtualmachinemanagercore
return;
}

if ($VMMServer.OpsMgrServer -ne $null)
{
$ProxyEnabled = CheckAgentProxy $VMMServer.OpsMgrServer $VMMServer.FQDN
$pBag.AddValue('AgentProxyEnabled', [bool]$ProxyEnabled)
}
else
{
$pBag.AddValue('AgentProxyEnabled', $false)
}
}
else
{
$evt.WriteEntry("Unable to retrieve RunAs account credentials to connect to VMMServer", $infoevent, 25931);
}

Remove-Module -Name "virtualmachinemanagercore"

$pBag
</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<!-- Create the workflow -->
<Composition>
<Node ID="CheckAgentProxyProbe">
<Node ID="SchedulerDS"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>