Hi there - I'm working with this PowerShell script was is adds a column to a content type -
[void][System.Reflection.Assembly]::Load("Microsoft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
[void][System.Reflection.Assembly]::Load("Microsoft.Sharepoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
[void][System.Reflection.Assembly]::Load("Microsoft.Office.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
$WA = "<http://webapp"
$webapp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup("$WA")
foreach($site in $webapp.Sites)
{
$web = $site.RootWeb
$ct=$web.ContentTypes["Document"];
$fieldAdd=$web.Fields["test"]
$fieldLink=New-Object Microsoft.SharePoint.SPFieldLink($fieldAdd)
$ct.FieldLinks.Add($fieldLink);
$ct.Update()
$web.Dispose()
$site.Dispose()
}
Now it's giving me this error: (abbreviated)
Cannot index into a null array
$ct=$web.ContentTypes[ <<<< "Document"];
Invalid Operation: (Document:String)
New-Object : Constructor not found. Cannot find an appropriate constructor for type Microsoft.SharePoint.SPFieldLink
Can anyone explain why this is happening and how to resolve?
I should add that despite this the script still works and adds the column - but only for Document content type - doesn't work for Item
Cheers
Jonj