Posts Tagged 'read text file'

Testing access to SharePoint pages

Let’s say you have a long list of SharePoint pages that need to be tested to verify that they’re permissioned correctly.  One way to do it is to take a non-privileged account (end user) and attempt to connect to each of the URLs.  If the page is locked down, you’ll get a page titled “Access denied”; otherwise, the page will load normally.

I recently responded to a thread on SharePoint TechNet about a similar issue and ended up writing a PowerShell script to address it.

The script below will read a text file containing a list of URLs (make sure to modify the source file path with your own path), and then call a function for each URL.  This function will open a new instance of IE, navigate to the URL, wait for the page to load, and then grab the title of the page.  If the user doesn’t have access to the page, the page title will contain “Access denied”; otherwise, the page title will be returned.  Run this script under the credentials of one of your end users.  If you’re trying to open individual documents (Word, Excel, etc.), you may need to modify the script so that it launches correct application (and closes it when done).


# This script will read a text file containing a list of URLs and attempt to connect to each URL.  Successful connection will return the page's title; otherwise, the script will return Access denied error.

# OpenIE function starts here...
# This function launches a new instance of IE and then navigates to the specified URL

function OpenIE($url)
{

if ($url -notlike "http://*")
{

$url = "http://" + $url

}
$ie = new-object -com "InternetExplorer.Application"

$ie.Visible = $true

$ie.Navigate($url)

# wait for IE to load the page

While( $ie.Busy )
{
[System.Threading.Thread]::Sleep(100)
}

# grab page title - if access is denied, the page title will say so

$Title = $ie.Document.Title

$ie.Quit()

return $Title

}

 

# *** Main script routine starts here ***
# specify your source file path here...

$SourceFilePath = "C:\Shared\list.txt"

write-host "Starting script..."

# read the source file into an array of strings, iterate through each one

$list = Get-Content $SourceFilePath

foreach ($item in $list)
{

$result = OpenIE($item)

write-host $item, ";" , $result

}

write-host "Finished."


RSS Information Week Headlines

  • An error has occurred; the feed is probably down. Try again later.

RSS SharePoint Team Blog

  • An error has occurred; the feed is probably down. Try again later.

RSS InfoPath Team Blog

  • An error has occurred; the feed is probably down. Try again later.

RSS Joel Oleson Blog

  • An error has occurred; the feed is probably down. Try again later.

RSS Bud Ratliff blog

  • An error has occurred; the feed is probably down. Try again later.

RSS Susan Hanley’s KM Blog

  • An error has occurred; the feed is probably down. Try again later.

Blog Stats

  • 401,897 hits