Adding a column to a content type powershell
-
Thursday, May 10, 2012 7:07 AM
hi!
I want on the site with the URL: "http://sp_3/export1" in the List
"Whereabout" add column "dfg" in the content "Пользователи" with powershell
// Whereabout - Местонахождение
my attempt :
PS C:\Windows\system32> $web = Get-SPWeb "http://sp_3/export1" PS C:\Windows\system32> $field = $web.Fields["dfg"] PS C:\Windows\system32> $ct = $web.ContentTypes["Пользователи"] PS C:\Windows\system32> $flink = new-Object Microsoft.SharePoint.SPFieldLink($field) PS C:\Windows\system32> $flink.DisplayName = $field.Title PS C:\Windows\system32> $ct.FieldLinks.Add($flink) Нельзя вызвать метод для выражения со значением NULL. строка:1 знак:19 + $ct.FieldLinks.Add <<<< ($flink) + CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNullwhy mistakes &
please help, thanks !!
All Replies
-
Thursday, May 10, 2012 12:17 PMtype in$ct.fieldlinks.addthis will show you what the add method is expecting.also look at $flink to make it contains what it should.
Justin Rich
http://jrich523.wordpress.com
PowerShell V3 Guide (Technet)
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
Tuesday, May 15, 2012 2:46 AMModerator
Hi,
PS > $spWeb = Get-SPWeb http://sp_3/export1 PS > $fields = $spWeb.Fields PS > $contentType = $spWeb.ContentTypes["Пользователи"]
PS > $taxField = $fields["dfg"]
PS > $contentType.FieldLinks.Add($taxField)
PS > $contentType.Update()
PS > $spWeb.Dispose()Or, please change
$ct.FieldLinks.Add($flink)
to
$ct.FieldLinks.Add($flink.ID)
Hope this helps.
Best Regards,
Yan Li
Yan Li
TechNet Community Support
- Edited by Yan Li_Microsoft Contingent Staff, Moderator Tuesday, May 15, 2012 2:47 AM
- Proposed As Answer by Yan Li_Microsoft Contingent Staff, Moderator Thursday, May 17, 2012 1:24 AM
- Marked As Answer by Yan Li_Microsoft Contingent Staff, Moderator Tuesday, May 22, 2012 12:38 AM

