Skip to content

Commit

Permalink
Merge branch 'code-review' into develop
Browse files Browse the repository at this point in the history
Søren Granfeldt committed Mar 27, 2024
2 parents dd1bd57 + b9a9350 commit a589d4a
Showing 8 changed files with 353 additions and 405 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# october 11, 2015 | soren granfeldt
# - version 5.5.0.3501
# november 8, 2015 | soren granfeldt
# - version 5.5.1.1017
param
(
)
# Author: Soren Granfeldt
# Date: October 11, 2015
# Version: 5.5.0.3501
# Description: This script copies necessary files for Granfeldt PowerShell Management Agent to FIM/MIM installation folders.

# November 8, 2015 - Update
# Author: Soren Granfeldt
# Version: 5.5.1.1017
# Description: Updated version of the script.

# Define filenames for the PowerShell Management Agent files
$maxmlfilename = "Granfeldt.PowerShell.ManagementAgent.xml"
$mafilename = "Granfeldt.PowerShell.ManagementAgent.dll"

# Attempt to retrieve the installation location of FIM/MIM from the registry
try
{
$location = get-itemproperty "hklm:\software\microsoft\forefront identity manager\2010\synchronization service" -erroraction stop | select -expand location
@@ -18,13 +23,15 @@ catch
break
}

# Append necessary paths to the installation location
$location = join-path $location "synchronization service"
write-debug "install-location: $location"
$extensionsfolder = join-path $location "extensions"
write-debug "install-location: $extensionsfolder"
$packagedmafolder = join-path $location "uishell\xmls\packagedmas"
write-debug "install-location: $packagedmafolder"

# Copy PowerShell Management Agent files to their respective folders
write-debug "copying $mafilename to $extensionsfolder"
copy-item "$mafilename" -destination "$extensionsfolder"
write-debug "copying $maxmlfilename to $packagedmafolder"
36 changes: 16 additions & 20 deletions Granfeldt.PowerShell.ManagementAgent/MA.Capabilities.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
using Microsoft.MetadirectoryServices;
// march 27, 2024 | soren granfeldt
// - code review and optimization

using Microsoft.MetadirectoryServices;
using System;

namespace Granfeldt
{
public partial class PowerShellManagementAgent : IDisposable, IMAExtensible2GetCapabilities, IMAExtensible2GetSchema, IMAExtensible2GetParameters, IMAExtensible2CallImport, IMAExtensible2CallExport, IMAExtensible2Password
{
MACapabilities IMAExtensible2GetCapabilities.Capabilities
{
get
{
Tracer.Enter("capabilities");
MACapabilities cap = new MACapabilities();
cap.ConcurrentOperation = true;
cap.DeltaImport = true;
cap.DistinguishedNameStyle = MADistinguishedNameStyle.Generic;
cap.ExportType = MAExportType.ObjectReplace;
cap.FullExport = true;
cap.ObjectConfirmation = MAObjectConfirmation.Normal;
cap.ObjectRename = false;
cap.NoReferenceValuesInFirstExport = false;
Tracer.Exit("capabilities");
return cap;
}
}
}
public MACapabilities Capabilities => new MACapabilities
{
ConcurrentOperation = true,
DeltaImport = true,
DistinguishedNameStyle = MADistinguishedNameStyle.Generic,
ExportType = MAExportType.ObjectReplace,
FullExport = true,
ObjectConfirmation = MAObjectConfirmation.Normal,
ObjectRename = false,
NoReferenceValuesInFirstExport = false
};
}

}
21 changes: 11 additions & 10 deletions Granfeldt.PowerShell.ManagementAgent/MA.Export.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// july 5, 2018, soren granfeldt
// - added schema psobject as parameter to export script
// march 27, 2024 | soren granfeldt
// - increased max export pagesize from 500 to 9999

using Microsoft.MetadirectoryServices;
using System;
@@ -14,24 +16,18 @@

namespace Granfeldt
{

public partial class PowerShellManagementAgent : IDisposable, IMAExtensible2GetCapabilities, IMAExtensible2GetSchema, IMAExtensible2GetParameters, IMAExtensible2CallImport, IMAExtensible2CallExport, IMAExtensible2Password
{
int exportBatchSize;
bool ExportSimpleObjects = true;
string ExportScript = null;
OperationType exportType;
Collection<PSObject> exportResults;
int ExportPageNumber = 0;

int IMAExtensible2CallExport.ExportDefaultPageSize
{
get { return 100; }
}
int IMAExtensible2CallExport.ExportMaxPageSize
{
get { return 500; }
}
void IMAExtensible2CallExport.OpenExportConnection(System.Collections.ObjectModel.KeyedCollection<string, ConfigParameter> configParameters, Schema types, OpenExportConnectionRunStep exportRunStep)
int IMAExtensible2CallExport.ExportDefaultPageSize => 100;
int IMAExtensible2CallExport.ExportMaxPageSize => 9999;
void IMAExtensible2CallExport.OpenExportConnection(System.Collections.ObjectModel.KeyedCollection<string, ConfigParameter> configParameters, Schema types, OpenExportConnectionRunStep exportRunStep)
{
Tracer.Enter("openexportconnection");
try
@@ -45,6 +41,8 @@ void IMAExtensible2CallExport.OpenExportConnection(System.Collections.ObjectMode
Tracer.TraceInformation("export-type '{0}'", exportType);
exportBatchSize = exportRunStep.BatchSize;
Tracer.TraceInformation("export-batch-size '{0}'", exportBatchSize);

ExportPageNumber = 0;
}
catch (Exception ex)
{
@@ -63,6 +61,8 @@ PutExportEntriesResults IMAExtensible2CallExport.PutExportEntries(IList<CSEntryC
PSDataCollection<PSObject> exportPipeline = new PSDataCollection<PSObject>();
try
{
ExportPageNumber++;

Command cmd = new Command(Path.GetFullPath(ExportScript));
cmd.Parameters.Add(new CommandParameter("Username", Username));
cmd.Parameters.Add(new CommandParameter("Password", Password));
@@ -76,6 +76,7 @@ PutExportEntriesResults IMAExtensible2CallExport.PutExportEntries(IList<CSEntryC

cmd.Parameters.Add(new CommandParameter("ExportType", exportType));
cmd.Parameters.Add(new CommandParameter("Schema", schemaPSObject));
cmd.Parameters.Add(new CommandParameter("ExportPageNumber", ExportPageNumber));

foreach (CSEntryChange csentryChange in csentries)
{
15 changes: 6 additions & 9 deletions Granfeldt.PowerShell.ManagementAgent/MA.Import.cs
Original file line number Diff line number Diff line change
@@ -26,18 +26,13 @@ public partial class PowerShellManagementAgent : IDisposable, IMAExtensible2GetC
object pageToken;
bool UsePagedImport = false;
string ImportScript = null;
int ImportPageNumber = 0;

List<PSObject> importResults;
List<CSEntryChange> csentryqueue = new List<CSEntryChange>();

public int ImportDefaultPageSize
{
get { return 100; }
}
public int ImportMaxPageSize
{
get { return 10000; }
}
public int ImportDefaultPageSize => 100;
public int ImportMaxPageSize => 10000;

Schema schema;
PSObject schemaPSObject;
@@ -115,6 +110,7 @@ public OpenImportConnectionResults OpenImportConnection(System.Collections.Objec
Tracer.TraceInformation("resetting-pipeline-results-and-counters");
importResults = new List<PSObject>();
pageToken = "";
ImportPageNumber = 0;

OpenImportConnectionResults oicr = new OpenImportConnectionResults();
ImportRunStepPageSize = openImportRunStep.PageSize;
@@ -151,6 +147,7 @@ public GetImportEntriesResults GetImportEntries(GetImportEntriesRunStep importRu

if (MoreToImport)
{
ImportPageNumber++;
MoreToImport = false; // make sure we set more-to-import to false; could be overwritten further down if pagedimports is true, though

// on first call, we set customdata to value from last successful run
@@ -170,6 +167,7 @@ public GetImportEntriesResults GetImportEntries(GetImportEntriesRunStep importRu
cmd.Parameters.Add(new CommandParameter("OperationType", importOperationType.ToString()));
cmd.Parameters.Add(new CommandParameter("UsePagedImport", UsePagedImport));
cmd.Parameters.Add(new CommandParameter("PageSize", ImportRunStepPageSize));
cmd.Parameters.Add(new CommandParameter("ImportPageNumber", ImportPageNumber));
cmd.Parameters.Add(new CommandParameter("Schema", schemaPSObject));

Tracer.TraceInformation("setting-custom-data '{0}'", importRunStep.CustomData);
@@ -188,7 +186,6 @@ public GetImportEntriesResults GetImportEntries(GetImportEntriesRunStep importRu

if (UsePagedImport)
{
// Tracer.TraceError("paged-import-not-supported-currently");
object moreToImportObject = powershell.Runspace.SessionStateProxy.GetVariable("MoreToImport");
if (moreToImportObject == null)
{
Loading

0 comments on commit a589d4a

Please sign in to comment.