Home > Uncategorized > SharePoint 2010: Get List of All Relative and Absolute URL’s in a Web Application using PowerShell

SharePoint 2010: Get List of All Relative and Absolute URL’s in a Web Application using PowerShell

In the process of configuring SharePoint 2010 to use ADFS Authentication I needed to extend the Web Application so that our external partners who are federated can access the portal with ADFS claims in a different zone, while our internal / non-federated users can still access the portal using Windows Auth with Kerberos.  When doing this you have to make sure there are no Absolute URL’s that might break the user experience.  Below is a PowerShell script I generated to search a Web Application for Relative and Absolute URLs so clean up can be performed before switching over to ADFS.

#GET WEB APPLICATION
$webApp = Get-SPWebApplication https://portal.com

#URL SEARCH STRING FOR ABSOLUTE URL
$searchURL = “*http*”

#CREATE .CSV FILE WITH HEADINGS FOR HYPERLINKS
“siteURL `t” + “Heading `t” + “hyperlink `t” + “Path” >> HYPERLINKS.csv

#FOREACH LOOP – LOOPS THROUGH ALL WEBS AND SUBSITES OF WEB APPLICATION
foreach ($web in $webApp | Get-SPSite -Limit All | Get-SPWeb -Limit All)

{
#GET PUBLISHING WEB FOR ALL WEBS IN WEB APPLICATION

$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
#GET GLOBAL NAVIGATION NODES
$nav = $pubWeb.Navigation.GlobalNavigationNodes
#GET QUICK LAUNCH NAVIGATION NODES

$nodes = $web.Navigation.QuickLaunch

#FOREACH LOOP – LOOPS THROUGH ALL GLOBAL NAVIGATION HEADINGS.
foreach ($qlHeading in $nav)

{
#GET GLOBAL NAVIGATION HEADING CHILDREN.

$qlLibraries = $qlHeading.Children

#FOREACH LOOP – LOOPS THROUGH ALL CHILDREN (LINKS) IN GLOBAL NAVIGATION HEADINGS.
foreach ($lib in $qlLibraries)

{
#IF STATEMENT TO CHECK IF HYPERLINK IS NOT NULL.

if ($lib.Url -ne $null)
{
write-host $qlHeading.Title
write-host $lib.Url
#IF STATEMENT TO CHECK HYPERLINK TO SEE IF IT MATCHES searchURL string.
if ($lib.Url -like $searchURL)

{
#IF HYPERLINK MATCHES THE $searchURL STRING THEN STORE “AbsoluteURL” STRING IN $path VARIABLE.

$path = “AbsoluteURL”
}
else
#IF HYPERLINK DOES NOT MATCH THE $searchURL  STRING THEN STORE “RelativeURL” STRING IN $path VARIABLE.

{
$path = “RelativeURL”
}
#WRITE GLOBAL NAVIGATION NODE RESULTS TO HYPERLINKS.csv FILE.

$web.Url + “`t” + $qlHeading.Title + “`t” + $lib.Url + “`t” + $path >> HYPERLINKS.csv
}
}
}
#FOREACH LOOP – LOOPS THROUGH ALL QUICK LAUNCH NAVIGATION NODES

foreach ($node in $nodes)
{
write-host $node.Title
write-host $node.Url
#IF STATEMENT TO CHECK HYPERLINK TO SEE IF IT MATCHES searchURL string.
if ($node.Url -like $searchURL)
{
#IF HYPERLINK MATCHES THE $searchURL STRING THEN STORE “AbsoluteURL” STRING IN $path VARIABLE.

$path = “AbsoluteURL”
}
else
{
#IF HYPERLINK DOES NOT MATCH THE $searchURL  STRING THEN STORE “RelativeURL” STRING IN $path VARIABLE.

$path = “RelativeURL”
}
#WRITE QUICK LAUNCH NAVIGATION NODE RESULTS TO HYPERLINKS.csv FILE.

$web.Url + “`t” + $qlHeading.Title + “`t” + $lib.Url + “`t” + $path >> HYPERLINKS.csv
}
}

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: