Get Domain from distinguished Name

Get Domain from FQDN:

get-domfqdn “CN=Test,OU=Orgunit,DC=contoso,DC=test”

will result in

contoso.test

function get-domfqdn ($fqdn)
 {
 $afqdn= $fqdn.split(",")
 $first = 0
 $Dom=""
 foreach ($pfqdn in $afqdn)
  {
  If ($pfqdn.contains("DC=") -eq $true)
   {
   If ($first -eq 1)
    {
           $Dom = $Dom+"."
    }
   $first = 1
   $Dom = $Dom+$pfqdn.replace("DC=","")
   }
  }
 return $dom
 }
This entry was posted in Information Technology and tagged , , . Bookmark the permalink.

Comments are closed.