I have written some Powershell script to iterate through each subsite in a web application, the aim of the script is then to find a list in each subsite with a specific name.

For example, our lists are called "Team Messages" and my aim is to turn on the open forms in a dialog.

The script I have is:

 Add-PSSnapin "Microsoft.SharePoint.PowerShell"

# Get All Web Applications
foreach($webApp in $WebApps)
    foreach ($SPsite in $webApp.Sites)
       # get the collection of webs
       foreach($SPweb in $SPsite.AllWebs)
            write-host $SPweb.title
               foreach($list in $web.Lists["Team Messages"])
                    $list.NavigateForFormsPages = $false;               

The code runs up to the final foreach loop where it then throws an error that is

Cannot index into a null array.

If anyone could point me in the right direction with this then it would be great!

  • This error is basically telling you that $list is empty because $web.Lists["Team Messages"] is returning empty. I would ask you to check if that first returns any results, you might want to check the exact name. Sep 19, 2016 at 15:18

1 Answer 1


I believe the issue is with your site reference.

The $web reference in foreach($list in $web.Lists["Team Messages"]) should actually be $SPweb

Also, confirm that the changes for modal dialogs have taken place as shown below:

enter image description here

  • This seems to work but it still doesn't set the forms to open in a dialog :( do you have any ideas with this please?
    – Adam13Hylo
    Sep 19, 2016 at 15:58
  • After running the powershell script, did you navigate to the list settings page for "Team Messages" list and confirm the change has taken place? I have added a screenshot of the page in my answer above. Sep 19, 2016 at 17:01
  • Hi Ransher, yes I did however unfortunately it was still set to no. I will keep debugging the Powershell to see if I can get the botom of it, thank you for your help.
    – Adam13Hylo
    Sep 19, 2016 at 20:06

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.