2.4 One Identity PoSh Connector
26 сентября 2019 г.
15:54
Пример конфига
"C:\distr\OIM81\Modules\TSB\dvd\AddOn\SDK\ADSample.xml"
\<\<qv-connector-beta11.xml>>
Структура файла:
-
Сначала определяем параметры, которые мы сможем задавать вне скрипта (ConnectionParameters)
-
Определяем CustomCommands, в которых будет содержаться команды, доступные на всем протяжении работы коннектора - такие как импорт модуля, создание сесии и т.п. - они не привязаны к какому то типу схемы
-
PredefinedCommands - команды, которые будут использоваться в типах схемы (Get-ADUser, Set-ADUser … ).
-
CommandSequence - будет последовательность команд, выполняющихся по порядку, указанном в Order, например, создание сессии. Там блоки Connect и Disconnect. Заканчивается Инициализация.
-
Для параметров указывается Source и Value. Source отвечает за то, откуда будет браться значение параметра. Value - откуда конкретно будет браться значение
"Source" = the source for the value. Available sources are
-
"ConnectionParameter" ... value is taken from a passed connection parameter) - из окна для параметров
-
"FixedValue" ... a fixed value
-
"FixedArray" ... a fixed array of values
-
"SwitchParameter" ... a Powershell switch Parameter
-
"GlobalVariable" ... value of a global variable
"Value" = meaning depends on "Source"
-
if source is "ConnectionParameter" then "Value" contains the name of the connection parameter
-
if source is "SwitchParameter" then "Value" can be omitted/has no effect
-
if source is "FixedValue" then "Value" contains a fixed value
-
if source is "FixedArray" then "Value" contains a comma seperated list of elements that are passed as an array
-
if source is "GlobalVariable" then "Value" contains the name of the variable to use.
-
To set a global variable use \$global:\<name> = \<value>
-
Дальше уже идут классы, например User и Group
A Property element contains the definition of Schema property.
-
"Name" = The name of the property
-
"DataType" = The data type (valid values are String, Int, Bool, DateTime)
-
"IsUniqueKey" = indicates, that the property can be used to identify an object instance
-
"IsMandatory" = indicates, that the property is mandatory
-
"IsAutofill" = indicates, that the value of this property is created by the system
-
"IsDisplay" = indicates, that the value of this property is used as a display
-
"IsRevision" = indicates, that the value of this property is used as revision
-
Указываются их свойства.
-
Указываются CommandMapping. В какой командлет должно быть отображенно значение свойства
-
Указываются ReturnBindings. Указываются командлеты для вычитывания конкретных свойств.
-
ModifiedBy. Определяет, какой командлет фактически записывает значение в систему.
-
После идет блок ReadConfiguration для чтения информации из системы целевой. Listing - указываются команды для получения всех объектов этого типа из системы. Указывается дополнительная последовательность для полной загрузки объекта со всеми свойствами, определенными в схеме
-
MethodConfiguration - для определения методов обработки объектов (Insert, Update, Delete)
Членство в группе
Передать полученный параметр в скрипт для дальнейшего использования
\<Property Name="id" DataType="String" IsUniqueKey="true" IsMandatory="true" IsAutoFill="true">
\<ReturnBindings>
\<Bind CommandResultOf="Get-Policies" Path="id.ToString()"/>
\</ReturnBindings>
\<CommandMappings>
\<Map ToCommand="Get-PolicyPath" Parameter="id" /> (вот здесь передаем параметр полученный в команду, которая принимает этот паратетр)
\</CommandMappings>
\</Property>
Затем, получаем значение из команды
\<Property Name="Path" DataType="String" IsMultivalue="true">
\<ReturnBindings>
\<Bind CommandResultOf="Get-PolicyPath" Path="Paths"/>
\</ReturnBindings>
\</Property>
И в конце
\<ReadConfiguration>
\<ListingCommand Command="Get-Policies">
\</ListingCommand>
\<CommandSequence>
\<Item Command="Get-Policy" Order="1" />
\<Item Command="Get-PolicyPath" Order="2">
\</Item>
\</CommandSequence>
\</ReadConfiguration>
Сама команда
\<CustomCommand Name="Get-PolicyPath">
\<![CDATA[
param(
[parameter(Mandatory=\$true,ValueFromPipelineByPropertyName=\$true)]
[ValidateNotNullOrEmpty()]
[String]\$id
)
\$paths = @()
\$policy = \$Global:policies | where id -eq \$id
foreach(\$m in \$policy.resources.path.values)
{
\$paths += \$m
}
New-Object PSObject -Property @{
Paths = \$paths
}
]]>
\</CustomCommand>
Troubleshooting
- Выводится список пользователей, но не отображается инфа по конкретному пользователю (записи)
В классе
\<ReadConfiguration>
\<ListingCommand Command="Get-Users">
\</ListingCommand>
\<CommandSequence>
\<Item Command="Get-User" Order="1">
\<SetParameter Param="id" Source="FixedValue" Value="id"/>
\</Item>
\</CommandSequence>
\</ReadConfiguration>
\</Class>
Item Command отвечает за получение инфы по конкретному пользователю (записи)
ListingCommand - получает список всех записей.
\<?xml version="1.0" encoding="utf-8" ?>
\<PowershellConnectorDefinition Id="SampleConnector" Version="1.0" Description="Sample Powershell Connector">
\<PluginAssemblies>
\<!--\<Assembly Path="VI.Projector.Exchange.Common.dll"/>-->
\</PluginAssemblies>
\<Initialization>
\<CustomCommands>
\<CustomCommand Name="Disconnect-SQL">
\<![CDATA[
\$SqlConnection.Close()
]]>
\</CustomCommand>
\<CustomCommand Name="Get-Users">
\<![CDATA[
\$SQLServer = "ip";
\$SQLDBName = "Directum";
\$user = "OneIMConnector";
\$pass = "pass";
\$SqlConnection = New-Object System.Data.SqlClient.SqlConnection;
\$SqlConnection.ConnectionString = "Server=[REDACTED_HOST]; Database=\$SQLDBName; User ID = [REDACTED_USER]; Password = [REDACTED];";
\$SqlCmd = New-Object System.Data.SqlClient.SqlCommand;
\$SqlCmd.Connection = \$SqlConnection;
\$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter;
\$SqlQuery = "SELECT * from OneIM_Accounts;"
\$SqlCmd.CommandText = \$SqlQuery;
\$SqlAdapter.SelectCommand = \$SqlCmd;
\$DataSet = New-Object System.Data.DataSet;
\$i=\$SqlAdapter.Fill(\$DataSet);
\$DataSet.Tables[0].Rows
]]>
\</CustomCommand>
\<CustomCommand Name="Get-Groups">
\<![CDATA[
\$SQLServer = "ip";
\$SQLDBName = "Directum";
\$uid = "Administrator";
\$pwd = "pass";
\$SqlQuery = "SELECT * from OIM_Groups;"
\$SqlConnection = New-Object System.Data.SqlClient.SqlConnection;
\$SqlConnection.ConnectionString = "Server=[REDACTED_HOST]; Database=\$SqlDBName; User ID = [REDACTED_USER]; Password = [REDACTED];"
\$SqlCmd = New-Object System.Data.SqlClient.SqlCommand;
\$SqlCmd.CommandText = \$SqlQuery;
\$SqlCmd.Connection = \$SqlConnection;
\$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter;
\$SqlAdapter.SelectCommand = \$SqlCmd;
\$DataSet1 = New-Object System.Data.DataSet;
\$i=\$SqlAdapter.Fill(\$DataSet1);
\$DataSet1.Tables[0].Rows
]]>
\</CustomCommand>
\<CustomCommand Name="Get-GroupsToAccount">
\<![CDATA[
\$SQLServer = "ip";
\$SQLDBName = "Directum";
\$uid = "Administrator";
\$pwd = "pass";
\$SqlQuery = "SELECT * from OIM_GroupsToAccount;"
\$SqlConnection = New-Object System.Data.SqlClient.SqlConnection;
\$SqlConnection.ConnectionString = "Server=[REDACTED_HOST]; Database=\$SqlDBName; User ID = [REDACTED_USER]; Password = [REDACTED];"
\$SqlCmd = New-Object System.Data.SqlClient.SqlCommand;
\$SqlCmd.CommandText = \$SqlQuery;
\$SqlCmd.Connection = \$SqlConnection;
\$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter;
\$SqlAdapter.SelectCommand = \$SqlCmd;
\$DataSet1 = New-Object System.Data.DataSet;
\$i=\$SqlAdapter.Fill(\$DataSet1);
\$DataSet1.Tables[0].Rows
]]>
\</CustomCommand>
\</CustomCommands>
\<PredefinedCommands>
\<Command Name="Get-Location"/>
\</PredefinedCommands>
\<EnvironmentInitialization>
\<Connect >
\<CommandSequence>
\<Item Command="Get-Location" Order="1"/>
\</CommandSequence>
\</Connect>
\<Disconnect>
\<CommandSequence>
\<Item Command="Disconnect-SQL" Order="1"/>
\</CommandSequence>
\</Disconnect>
\</EnvironmentInitialization>
\</Initialization>
\<Schema>
\<Class Name="Group">
\<Properties>
\<Property Name="GroupID" DataType="String" IsUniqueKey="true" >
\<ReturnBindings>
\<Bind CommandResultOf="Get-Groups" Path="GroupID"/>
\</ReturnBindings>
\</Property>
\<Property Name="GroupName" DataType="String" IsUniqueKey="false" >
\<ReturnBindings>
\<Bind CommandResultOf="Get-Groups" Path="GroupName"/>
\</ReturnBindings>
\</Property>
\</Properties>
\<ReadConfiguration>
\<ListingCommand Command="Get-Groups">
\</ListingCommand>
\<CommandSequence>
\<Item Command="Get-Groups" Order="1" >
\</Item>
\</CommandSequence>
\</ReadConfiguration>
\</Class>
\<Class Name="User">
\<Properties>
\<Property Name="LoginName" DataType="String" IsUniqueKey="true" >
\<ReturnBindings>
\<Bind CommandResultOf="Get-Users" Path="LoginName"/>
\</ReturnBindings>
\</Property>
\<Property Name="FullName" DataType="String" IsUniqueKey="false" >
\<ReturnBindings>
\<Bind CommandResultOf="Get-Users" Path="FullName"/>
\</ReturnBindings>
\</Property>
\<Property Name="TabNum" DataType="String" IsUniqueKey="false" >
\<ReturnBindings>
\<Bind CommandResultOf="Get-Users" Path="TabNum"/>
\</ReturnBindings>
\</Property>
\<Property Name="Status" DataType="String" IsUniqueKey="false">
\<ReturnBindings>
\<Bind CommandResultOf="Get-Users" Path="Status"/>
\</ReturnBindings>
\</Property>
\</Properties>
\<ReadConfiguration>
\<ListingCommand Command="Get-Users">
\</ListingCommand>
\<CommandSequence>
\<Item Command="Get-Users" Order="1" >
\</Item>
\</CommandSequence>
\</ReadConfiguration>
\</Class>
\<Class Name="GroupsToAccount">
\<Properties>
\<Property Name="UserName" DataType="String" IsUniqueKey="true" >
\<ReturnBindings>
\<Bind CommandResultOf="Get-GroupsToAccount" Path="UserName"/>
\</ReturnBindings>
\</Property>
\<Property Name="GroupName" DataType="String" IsUniqueKey="true" >
\<ReturnBindings>
\<Bind CommandResultOf="Get-GroupsToAccount" Path="GroupName"/>
\</ReturnBindings>
\</Property>
\</Properties>
\<ReadConfiguration>
\<ListingCommand Command="Get-GroupsToAccount">
\</ListingCommand>
\<CommandSequence>
\<Item Command="Get-GroupsToAccount" Order="1" >
\</Item>
\</CommandSequence>
\</ReadConfiguration>
\</Class>
\</Schema>
\</PowershellConnectorDefinition>
