Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

New-Object : Constructor not found. Cannot find an appropriate constructor for type Microsoft.SharePoint.SPFieldLink

$
0
0

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



Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>