Hello, I'm trying to build a custom pattern to extend some AD User information.
I found there is a property called "Extended Information" that can be used to extend data.
So I built a custom pattern that uses a query to retrieve all attributes from an AD User
(Get-ADUser -Filter * -Properties *).
My question is:
How can I extend a User (object) information at code level?
I only succeded extending the host info.
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<!--
© Atlassian
-->
<ScanPattern xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Version>1.0.0</Version>
<PatternID>ExtInfoPatternUserPS</PatternID>
<OrderNr>336</OrderNr>
<ProcessType>PowerShellExecute</ProcessType>
<PatternType>User</PatternType>
<Command>
<![CDATA[
Get-ADUser -Filter * -Properties *
]]>
</Command>
<Processing>
<![CDATA[
using System;
using System.Management;
using Insight.Discovery.Tools;
using Insight.Discovery.InfoClasses;
using System.Collections.Generic;
using Insight.Discovery.InfoClasses.CommandResult.ResultTypes;
namespace Insight.Discovery {
public class PatternExec {
public void PerformAction(object[] parameters)
{
HostInfo hostInfo = (HostInfo)parameters[2];
try
{
PowerShellExecuteResult result = (PowerShellExecuteResult)parameters[0];
string input = result;
if (input != string.Empty)
{
result.LogResult();
string[] lines = input.Split('\n');
if (hostInfo.ExtendedInformations.IsNullOrEmpty()) hostInfo.ExtendedInformations = new List<ExtendedInformation>();
ExtendedInformation displayNameInfo = new ExtendedInformation() { Name = "DisplayName", Value = string.Empty };
ExtendedInformation departmentInfo = new ExtendedInformation() { Name = "Department", Value = string.Empty };
ExtendedInformation samAccountNameInfo = new ExtendedInformation() { Name = "SamAccountName", Value = string.Empty };
for (int i = 0; i < lines.Length; i++)
{
if (lines[i].Contains(":"))
{
string variable = lines[i].Substring(0, lines[i].IndexOf(":", StringComparison.Ordinal)).Trim();
string value = lines[i].Substring(lines[i].IndexOf(":", StringComparison.Ordinal) + 1).Trim();
if (!string.IsNullOrEmpty(variable) && !string.IsNullOrEmpty(value))
{
switch (variable)
{
case "DisplayName":
displayNameInfo.Value = value;
break;
case "Department":
departmentInfo.Value = value;
break;
case "SamAccountName":
samAccountNameInfo.Value = value;
break;
}
}
}
}
if (!string.IsNullOrEmpty(displayNameInfo.Value))
{
displayNameInfo.Value = displayNameInfo.Value.Substring(0, displayNameInfo.Value.Length - 1);
hostInfo.ExtendedInformations.Add(displayNameInfo);
}
if (!string.IsNullOrEmpty(departmentInfo.Value))
{
departmentInfo.Value = departmentInfo.Value.Substring(0, departmentInfo.Value.Length - 1);
hostInfo.ExtendedInformations.Add(departmentInfo);
}
if (!string.IsNullOrEmpty(samAccountNameInfo.Value))
{
samAccountNameInfo.Value = samAccountNameInfo.Value.Substring(0, samAccountNameInfo.Value.Length - 1);
hostInfo.ExtendedInformations.Add(samAccountNameInfo);
}
}
}
catch (Exception ex)
{ LogService.Instance.LogDebug("Error getting Users Information", ex); }
}
}
}
]]>
</Processing>
</ScanPattern>