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
} |