Advertisement
Old-Lost

Split-DN

Jul 25th, 2017
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Split-DN {
  2.     [CmdletBinding(DefaultParameterSetName = 'Parent')][OutputType([string])]
  3.     param (
  4.         [Parameter(Mandatory, Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)][AllowNull()][AllowEmptyString()][AllowEmptyCollection()][Alias('DN')][string[]]$DistinguishedName,
  5.         [Parameter(ParameterSetName = 'Parent')][switch]$Parent = $true,
  6.         [Parameter(ParameterSetName = 'Leaf')][switch]$Leaf
  7.     )
  8.     Process {
  9.         switch ($PSCmdlet.ParameterSetName) {
  10.             'Leaf' {
  11.                 $DistinguishedName -replace '\A((:?CN|OU|DC)=.*?),(CN|OU|DC)=.*', '$1'
  12.                 break
  13.             }
  14.             default {
  15.                 $DistinguishedName -replace '\A.*?,(CN|OU|DC)=', '$1='
  16.             }
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement