Skip to content

Commit

Permalink
Updated implementation
Browse files Browse the repository at this point in the history
Find-LdapObject: Added support for sorting of attributes on returned objects
Transforms: Simplified implementation
  • Loading branch information
jformacek committed Dec 28, 2020
1 parent e7e6bb4 commit b00d959
Show file tree
Hide file tree
Showing 26 changed files with 194 additions and 258 deletions.
10 changes: 7 additions & 3 deletions S.DS.P.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,16 @@
# No need to specify prop as binary if transform loaded for the prop - binary'ness of prop is defined in transform
# Added CertificateValidationFlags param to Get-LdapConnection to allow control trust to server certificate
# Added Client certificate auth for LDAP connection
# 28.12.2020, 2.1.1, Jiri Formacek, Changed default of RangeSize to -1, which causes that ranged attribute retrieval is not used by default and all objects are loaded within single request
# Simplified implementation of transforms and added some
# Added support for alphabetically sorting of attributes on returned objects
@{

# Script module or binary module file associated with this manifest
RootModule = '.\S.DS.P.psm1'

# Version number of this module.
ModuleVersion = '2.1.0'
ModuleVersion = '2.1.1'

# ID used to uniquely identify this module
GUID = '766cbbc0-85b9-4773-b4db-2fa86cd771ff'
Expand Down Expand Up @@ -147,7 +150,8 @@
'Add-LdapObject','Remove-LdapObject',
'Rename-LdapObject',
'Register-LdapAttributeTransform','Unregister-LdapAttributeTransform',
'Get-LdapAttributeTransform'
'Get-LdapAttributeTransform',
'New-LdapAttributeTransformDefinition'

# Variables to export from this module
VariablesToExport = @()
Expand Down Expand Up @@ -181,7 +185,7 @@
# ReleaseNotes = ''

# Prerelease string of this module
#Prerelease = 'beta5'
Prerelease = 'beta1'

# Flag to indicate whether the module requires explicit user acceptance for install/update/save
RequireLicenseAcceptance = $false
Expand Down
144 changes: 110 additions & 34 deletions S.DS.P.psm1

Large diffs are not rendered by default.

11 changes: 2 additions & 9 deletions TransformTemplate/_Template.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ if($FullLoad)
# CSharp types added via Add-Type are supported
}

#add attributes that can be used with this transform
#add attributes that can be processed by this transform
$SupportedAttributes = @()

# This is mandatory definition of transform that is expected by transform architecture
$prop=[Ordered]@{
BinaryInput=$false
SupportedAttributes=$SupportedAttributes
OnLoad = $null
OnSave = $null
}
$codeBlock = new-object PSCustomObject -property $prop
$codeBlock = New-LdapAttributeTransformDefinition -SupportedAttributes $SupportedAttributes
$codeBlock.OnLoad = {
param(
[object[]]$Values
Expand Down Expand Up @@ -50,4 +44,3 @@ $codeBlock.OnSave = {
}
}
$codeBlock

11 changes: 3 additions & 8 deletions Transforms/Boolean.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@ if($FullLoad)
$SupportedAttributes = @('IsCriticalSystemObject')

# This is mandatory definition of transform that is expected by transform architecture
$prop=[Ordered]@{
BinaryInput=$false
SupportedAttributes=$SupportedAttributes
OnLoad = $null
OnSave = $null
}
$codeBlock = new-object PSCustomObject -property $prop
$codeBlock= New-LdapAttributeTransformDefinition -SupportedAttributes $SupportedAttributes

$codeBlock.OnLoad = {
param(
[object[]]$Values
[string[]]$Values
)
Process
{
Expand Down
10 changes: 2 additions & 8 deletions Transforms/Certificate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ param (
$FullLoad
)

$prop=[Ordered]@{
BinaryInput=$true
SupportedAttributes=@('userCertificate','userCert')
OnLoad = $null
OnSave = $null
}
$codeBlock = new-object PSCustomObject -property $prop
$codeBlock= New-LdapAttributeTransformDefinition -SupportedAttributes @('userCertificate','userCert') -BinaryInput
$codeBlock.OnLoad = {
param(
[object[]]$Values
[byte[][]]$Values
)
Process
{
Expand Down
47 changes: 5 additions & 42 deletions Transforms/GeneralizedTime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,11 @@ if($FullLoad)
# Add any types that are used by transforms
# CSharp types added via Add-Type are supported
}
$codeBlock= New-LdapAttributeTransformDefinition -SupportedAttributes @('createTimestamp','dsCorePropagationData','modifyTimestamp','whenCreated','whenChanged','msExchWhenMailboxCreated')

New-Object PSCustomObject -property ([ordered]@{
SupportedAttributes=@('createTimestamp','dsCorePropagationData','modifyTimestamp','whenCreated','whenChanged','msExchWhenMailboxCreated')
OnLoad = {
param(
[object[]]$Values
)
Process
{
foreach($Value in $Values)
{
[DateTime]::ParseExact($value,'yyyyMMddHHmmss.fK',[System.Globalization.CultureInfo]::InvariantCulture,[System.Globalization.DateTimeStyles]::AssumeUniversal)
}
}
}
OnSave = {
param(
[DateTime[]]$Values
)

Process
{
foreach($Value in $Values)
{
$value.ToUniversalTime().ToString('yyyyMMddHHmmss.0Z')
}
}
}
})

<#
#add attributes that can be used with this transform
$SupportedAttributes = @('whenCreated','whenChanged')
# This is mandatory definition of transform that is expected by transform architecture
$prop=[Ordered]@{
SupportedAttributes=$SupportedAttributes
OnLoad = $null
OnSave = $null
}
$codeBlock = new-object PSCustomObject -property $prop
$codeBlock.OnLoad = {
param(
[object[]]$Values
[string[]]$Values
)
Process
{
Expand All @@ -64,6 +25,7 @@ $codeBlock.OnLoad = {
}
}
}

$codeBlock.OnSave = {
param(
[DateTime[]]$Values
Expand All @@ -77,5 +39,6 @@ $codeBlock.OnSave = {
}
}
}

$codeBlock
#>

9 changes: 2 additions & 7 deletions Transforms/Integer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ if($FullLoad)
$SupportedAttributes = @('codePage','countryCode','logonCount','msDS-Approx-Immed-Subordinates','ms-DS-KeyVersionNumber','ms-DS-ManagedPasswordInterval')

# This is mandatory definition of transform that is expected by transform architecture
$prop=[Ordered]@{
BinaryInput=$false
SupportedAttributes=$SupportedAttributes
OnLoad = $null
OnSave = $null
}
$codeBlock = new-object PSCustomObject -property $prop
$codeBlock= New-LdapAttributeTransformDefinition -SupportedAttributes $SupportedAttributes

$codeBlock.OnLoad = {
param(
[string[]]$Values
Expand Down
8 changes: 1 addition & 7 deletions Transforms/Long.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ if($FullLoad)
$SupportedAttributes = @('uSNChanged', 'uSNCreated')

# This is mandatory definition of transform that is expected by transform architecture
$prop=[Ordered]@{
BinaryInput=$false
SupportedAttributes=$SupportedAttributes
OnLoad = $null
OnSave = $null
}
$codeBlock = new-object PSCustomObject -property $prop
$codeBlock= New-LdapAttributeTransformDefinition -SupportedAttributes $SupportedAttributes
$codeBlock.OnLoad = {
param(
[string[]]$Values
Expand Down
10 changes: 3 additions & 7 deletions Transforms/ProxyAddress.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,11 @@ public class ProxyAddress:IEquatable<ProxyAddress>
'@
}

$prop=[Ordered]@{
SupportedAttributes=@('proxyAddresses','targetAddress')
OnLoad = $null
OnSave = $null
}
$codeBlock = new-object PSCustomObject -property $prop
$codeBlock= New-LdapAttributeTransformDefinition -SupportedAttributes @('proxyAddresses','targetAddress')

$codeBlock.OnLoad = {
param(
[object[]]$Values
[string[]]$Values
)
Process
{
Expand Down
11 changes: 3 additions & 8 deletions Transforms/SamAccountType.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,17 @@ public enum SamAccountType
}
'@
}
$codeBlock= New-LdapAttributeTransformDefinition -SupportedAttributes @('sAMAccountType')

$prop=[Ordered]@{
SupportedAttributes=@('sAMAccountType')
OnLoad = $null
OnSave = $null
}
$codeBlock = new-object PSCustomObject -property $prop
$codeBlock.OnLoad = {
param(
[int[]]$Values
[string[]]$Values
)
Process
{
foreach($Value in $Values)
{
[SamAccountType].GetEnumValues().ForEach({if($Value -eq $_) {"$_"}})
[SamAccountType].GetEnumValues().ForEach({if([int]$Value -eq $_) {"$_"}})
}
}
}
Expand Down
10 changes: 3 additions & 7 deletions Transforms/WindowsHelloKeyInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,11 @@ public class KeyCredentialInfo
$SupportedAttributes = @('msDs-KeyCredentialLink')

# This is mandatory definition of transform that is expected by transform architecture
$prop=[Ordered]@{
SupportedAttributes=$SupportedAttributes
OnLoad = $null
OnSave = $null
}
$codeBlock = new-object PSCustomObject -property $prop
$codeBlock= New-LdapAttributeTransformDefinition -SupportedAttributes $SupportedAttributes

$codeBlock.OnLoad = {
param(
[object[]]$Values
[string[]]$Values
)
Process
{
Expand Down
9 changes: 2 additions & 7 deletions Transforms/admpwd.e.pwd.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,8 @@ public class AdmPwdPassword
$SupportedAttributes = @('ms-Mcs-AdmPwd')

# This is mandatory definition of transform that is expected by transform architecture
$prop=[Ordered]@{
BinaryInput=$false
SupportedAttributes=$SupportedAttributes
OnLoad = $null
OnSave = $null
}
$codeBlock = new-object PSCustomObject -property $prop
$codeBlock= New-LdapAttributeTransformDefinition -SupportedAttributes $SupportedAttributes

$codeBlock.OnLoad = {
param(
[string[]]$Values
Expand Down
9 changes: 2 additions & 7 deletions Transforms/admpwd.e.pwdhistory.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,8 @@ public class AdmPwdPasswordHistory
$SupportedAttributes = @('ms-Mcs-AdmPwdHistory')

# This is mandatory definition of transform that is expected by transform architecture
$prop=[Ordered]@{
BinaryInput=$false
SupportedAttributes=$SupportedAttributes
OnLoad = $null
OnSave = $null
}
$codeBlock = new-object PSCustomObject -property $prop
$codeBlock= New-LdapAttributeTransformDefinition -SupportedAttributes $SupportedAttributes

$codeBlock.OnLoad = {
param(
[string[]]$Values
Expand Down
24 changes: 14 additions & 10 deletions Transforms/fileTime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@ param (
$FullLoad
)

$prop=[Ordered]@{
SupportedAttributes=@('accountExpires','badPasswordTime','lastLogon','lastLogonTimestamp','ms-Mcs-AdmPwdExpirationTime','msDS-UserPasswordExpiryTimeComputed','pwdLastSet')
OnLoad = $null
OnSave = $null
}
$codeBlock = new-object PSCustomObject -property $prop
$codeBlock= New-LdapAttributeTransformDefinition -SupportedAttributes @('accountExpires','badPasswordTime','lastLogon','lastLogonTimestamp','ms-Mcs-AdmPwdExpirationTime','msDS-UserPasswordExpiryTimeComputed','pwdLastSet')

$codeBlock.OnLoad = {
param(
[long[]]$Values
[string[]]$Values
)
Process
{
foreach($Value in $Values)
{
try {
[DateTime]::FromFileTimeUtc($Value)
[DateTime]::FromFileTimeUtc([long]$Value)
}
catch {
#value outside of range for filetime
Expand All @@ -32,14 +28,22 @@ $codeBlock.OnLoad = {
}
$codeBlock.OnSave = {
param(
[DateTime[]]$Values
[Object[]]$Values
)

Process
{
foreach($Value in $Values)
{
$Value.ToFileTimeUtc()
#standard expiration
if($value -is [datetime]) {
$Value.ToFileTimeUtc()
continue;
}
#values that did not transform to DateTime in OnLoad
if($value -is [string]) {
$value
}
}
}
}
Expand Down
20 changes: 8 additions & 12 deletions Transforms/groupType.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,36 @@ if($FullLoad)
Add-Type @'
using System;
[Flags]
public enum GroupType
public enum GroupType: uint
{
Global = 0x00000002,
Local = 0x00000004,
Universal = 0x00000008,
Security = unchecked((int)0x80000000)
Security = 0x80000000
}
'@
}

$prop=[Ordered]@{
SupportedAttributes=@('groupType')
OnLoad = $null
OnSave = $null
}
$codeBlock = new-object PSCustomObject -property $prop
$codeBlock= New-LdapAttributeTransformDefinition -SupportedAttributes @('groupType')

$codeBlock.OnLoad = {
param(
[int[]]$Values
[string[]]$Values
)
Process
{
[GroupType].GetEnumValues().ForEach({if(($Value -band $_) -eq $_) {"$_"}})
[GroupType].GetEnumValues().ForEach({if(([uint]$Value -band $_) -eq $_) {"$_"}})
}
}
$codeBlock.OnSave = {
param(
[System.String[]]$Values
[GroupType[]]$Values
)

Process
{
$retVal = 0
$Values.ForEach({ [GroupType]$val=$_; $retVal+=$val})
$Values.ForEach({ $retVal+=$_})
$retVal
}
}
Expand Down
Loading

0 comments on commit b00d959

Please sign in to comment.