I am needing to add the LinkFilenameNoMenu ("Name(linked to document with edit menu") column to a view within a library on multiple SharePoint sites. This is what I have:
Add-PSSnapin Microsoft.SharePoint.PowerShell
$InvFile="ProjectURLs2.csv"
# Get Data from Inventory CSV File
$FileExists = (Test-Path $InvFile -PathType Leaf)
if ($FileExists) {
"Loading $InvFile for processing..."
$tblData = import-csv $InvFile
} else {
"$InvFile not found - stopping import!"
exit
}
foreach ($row in $tblData)
{
$ProjectURL = $row."ProjectURL".ToString()
$web = Get-SPWeb "$ProjectURL"
$list = $web.Lists["Document Library"]
$View = $List.Views["All Documents without Folders"]
$field = $List.Fields["SPBuiltInFieldId.LinkFilenameNoMenu"]
$View.ViewFields.Add($field)
$view.Update()
}
I am getting
"Exception calling "Add" with "1" arguments(S): "Object reference not set to an instance of an object"" on the line for "$View.ViewFields.Add($field).
Any thoughts on how I should modify this so that I can add this column to my library views?