Repository navigation
Fix DirectorySync.EntraConnect PSRemoting integration #285
Description
Description
The IdLE.Provider.DirectorySync.EntraConnect currently requires consumers to manually construct PSRemoting sessions and wrap them in custom objects with InvokeCommand methods before passing them through a broker. This is unnecessarily complex for a straightforward remote execution scenario.
Steps to Reproduce (Current Broken Workflow)
-
Create PSRemoting session externally:
$adConnectSession = New-PSSession -ComputerName 'ad-sync1.corp.local' -Credential $syncCred
-
Wrap session in custom object with ScriptMethod:
$authSessionWrapper = [pscustomobject]@{ PSTypeName = 'IdLE.AuthSession.PSRemoting'; Session = $adConnectSession } $authSessionWrapper | Add-Member -MemberType ScriptMethod -Name InvokeCommand -Value { ... }
-
Create broker and pass wrapper:
$authSessions = New-IdleAuthSession -SessionMap @{ @{ AuthSessionName = 'EntraConnect' } = @{ AuthSessionType = 'PSRemoting'; Credential = $authSessionWrapper } }
Problem: Broker validation fails with "The property 'Methods' cannot be found on this object" errors during execution. Workaround requires custom broker implementation.
Provider should:
- Accept
ComputerNameas direct parameter in Step.With - Receive credentials via standard
AuthSessionBroker(AuthSessionType='Credential') - Build and manage PSRemoting session internally
- Simplify workflow config to flat structure
Proposed Consumer Setup:
$syncCred = Get-Credential -Message "ADSync Admin account"
$authSessions = New-IdleAuthSession `
-DefaultAuthSession $syncCred `
-AuthSessionType 'Credential'
$providers = @{
DirectorySync = New-IdleEntraConnectDirectorySyncProvider
AuthSessionBroker = $authSessions
}
$plan = New-IdlePlan -WorkflowPath $workflowFile -Request $request -Providers $providers
$result = Invoke-IdlePlan -Plan $planProposed Workflow Config:
@{
Name = 'ADSync Trigger'
LifecycleEvent = 'Operational'
Steps = @(
@{
Name = 'ADSync'
Type = 'IdLE.Step.TriggerDirectorySync'
With = @{
Provider = 'DirectorySync'
ComputerName = 'ad-sync1.corp.local'
AuthSessionName = 'EntraConnect'
PolicyType = 'Delta'
Wait = $true
TimeoutSeconds = 300
}
}
)
}Actual Behavior
Currently, the only way to get it working is to build a custom broker that bypasses validation:
$broker = [pscustomobject]@{ PSTypeName = 'IdLE.AuthSessionBroker'; Session = $authSessionWrapper }
$broker | Add-Member -MemberType ScriptMethod -Name AcquireAuthSession -Value {
param([string] $Name, [hashtable] $Options)
return $this.Session
} -ForceThis is a workaround, not a supported pattern.
Environment
- PowerShell version: 7.4+
- IdLE version: main branch
- Provider: IdLE.Provider.DirectorySync.EntraConnect
- Step: IdLE.Steps.DirectorySync (Invoke-IdleStepTriggerDirectorySync)
Acceptance Criteria
- Provider accepts
ComputerNameparameter in Step.With - Provider builds PSRemoting session internally with provided credential
- Session cleanup handled in finally block
- Works seamlessly with
AuthSessionType='Credential'broker - Existing tests updated to reflect new flow
- New provider contract tests added for ComputerName + Credential pattern
- Step documentation updated
- Example workflow(s) updated
Suggested Implementation
Provider changes:
- Store
ComputerNamefrom Step.With context - In
StartSyncCycle()andGetSyncCycleState(): build session from$AuthSession(Credential) + stored ComputerName - Execute commands on remote session
- Clean up session in finally block
Step changes:
- Accept and validate
ComputerNamein With parameters - Pass it to provider context
Testing:
- Add contract test: Provider + Step with PSRemoting
- Update existing mock tests to verify new pattern
Related Issues
Discovered while testing DirectorySync trigger with Entra Connect ADSync server (#xyz)
Additional Context
This is an improvement to provider autonomy and separation of concerns. Currently, network/session management leaks into IdLE.Core broker logic, which should be simpler and more generic.
Activity