Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Split-DN {
- [CmdletBinding(DefaultParameterSetName = 'Parent')][OutputType([string])]
- param (
- [Parameter(Mandatory, Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)][AllowNull()][AllowEmptyString()][AllowEmptyCollection()][Alias('DN')][string[]]$DistinguishedName,
- [Parameter(ParameterSetName = 'Parent')][switch]$Parent = $true,
- [Parameter(ParameterSetName = 'Leaf')][switch]$Leaf
- )
- Process {
- switch ($PSCmdlet.ParameterSetName) {
- 'Leaf' {
- $DistinguishedName -replace '\A((:?CN|OU|DC)=.*?),(CN|OU|DC)=.*', '$1'
- break
- }
- default {
- $DistinguishedName -replace '\A.*?,(CN|OU|DC)=', '$1='
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement