being both quite new to both PowerShell and SharePoint 2010 I'm wondering if there is any way to make a script for searching a lists for links that begins in a certain way? I want to find all the links that starts with "http", "https" or "file//" and since I'm not quite up to speed with neither PS or SP2010 I felt it was better to ask before I started doing anything. Thx for any help or pointers, even smug remarks are appreciated if they in some way help out!

1 Answer 1


If I understand you correctly, by 'searching a list for links' you actually need to search list for HyperLink fields?

If that is true here is simple PS script that search all list in given web for links starting by "http", "https" or "file":

$web = Get-SPWeb "http://mycoolsite"
$result = @() #Edited
# Iterate lists
foreach ($list in $web.Lists) {
    # First find all HyperLink fields in list
    $fields = @()
    foreach ($field in $list.Fields) {
        if ($field.TypeAsString -eq "URL") {
            $fields = $fields + $field.Title        

    # Skip list because there are no Hyperlink fields
    if($fields.Count -eq 0) { continue }
    # Iterate list items NOTE: this can be slow
    foreach ($item in $list.Items) {
        # Iterate HyperLink fields
        foreach ($field in $fields) {
            # Get field value
            $fldValue = $item[$field]
            # Skip if null
            if($fldValue -ne $null) { 
                # Check for http: https: or file:
                if($fldValue.Contains("http://") -or  $fldValue.Contains("https://") -or $fldValue.Contains("file://")) {
                    $result += $list.Title + " " +  $item["ID"] + " " + $fldValue #Edited 
$result | Out-File file_links.txt #Edited


I edited my original code to answer additional question posted in comments (how to save results as txt file?). I made minor adjustments and marked them with #Edited. Please note this is not only option to export results but it is one that required minimal changes in original script.

  • This is exactly what I was looking for, huge thanks!!!
    – K.W
    Sep 13, 2011 at 13:37
  • 1
    K.W. - This is a solution that should work great for your needs, but just be aware of Vedran's comment in the code. Iterating over so many list items can be very slow performing if you have a large collection of lists. Sep 13, 2011 at 13:47
  • Does $web need to be disposed of in this case? Sep 13, 2011 at 13:47
  • 1
    @Tim - look at this: stackoverflow.com/questions/1999858/… Sep 13, 2011 at 14:01
  • Thanks! I was working with what the answer said yesterday. Ad-hoc scripts that were not being disposed. Sep 13, 2011 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.