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
$WebApps=Get-SPWebApplication
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;
$list.Update();
}
}
}
}
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!

$listis 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.