Get server and site name from url

09/01/2012 21:53


function GetServerNameFromUrl(
    [string]$url
)
{
$server=$url.split("/")
return $server[2]
}


function GetServerFromUrl(
    [string]$url
)
{
$first=$url.IndexOf('/')
$short=$url.substring($first+2,$url.length-$first-2)
$server=$url.substring(0, $short.IndexOf('/')+$first+2)
return $server
}

#gets site part from url, if its only server, returns empty string

 

function GetSiteFromUrl(
    [string]$url
)
{
$first=$url.IndexOf('/')
$short=$url.substring($first+2,$url.length-$first-2)
$index=$short.IndexOf('/')
$site=$short.substring($index+1, $short.length-$index-1)
$server=($url.split("/"))[2]
if ($server -eq $site)
    {
    return ""
    }
else
    {   
    return $site
    }
}
$url="https://portal.avd.com/sites/newsitecollection"
$a= GetSiteFromUrl $url
$b= GetServerFromUrl $url
write-host "Server je: " $b " a site je: " $a