Private/Storage/Get-PukRecord.ps1
|
function Get-PukRecord { [CmdletBinding()] [OutputType([psobject])] param( [Parameter(Mandatory)] [psobject]$Config, [Parameter(Mandatory)] [System.Security.Cryptography.X509Certificates.X509Certificate2]$Certificate, [string]$Server, [Parameter(ParameterSetName = 'ByDistinguishedName', Mandatory)] [string]$DistinguishedName, [Parameter(ParameterSetName = 'BySerialNumber', Mandatory)] [string]$SerialNumber ) $record = switch ($Config.hosting.model) { 'FlatFile' { $params = @{ Path = $Config.hosting.flatFile.path; Certificate = $Certificate } if ($PSCmdlet.ParameterSetName -eq 'ByDistinguishedName') { $params.DistinguishedName = $DistinguishedName } else { $params.SerialNumber = $SerialNumber } Get-PukFlatFileRecord @params } 'ActiveDirectory' { $params = @{ AttributeName = $Config.hosting.activeDirectory.attributeName; Certificate = $Certificate } $effectiveServer = if ($Server) { $Server } else { $Config.hosting.activeDirectory.server } if ($effectiveServer) { $params.Server = $effectiveServer } if ($PSCmdlet.ParameterSetName -eq 'ByDistinguishedName') { $params.DistinguishedName = $DistinguishedName } else { $params.SerialNumber = $SerialNumber if ($Config.hosting.activeDirectory.searchBase) { $params.SearchBase = $Config.hosting.activeDirectory.searchBase } } Get-PukAdRecord @params } default { throw "Unsupported hosting model '$($Config.hosting.model)'." } } if (-not $record) { return $null } return [PSCustomObject]@{ PSTypeName = 'PWSHPUKMGT.Record' DistinguishedName = $record.DistinguishedName SerialNumber = $record.SerialNumber Puk = $record.Puk } } |