1

PowerShellを使用してリストフィールドのプロパティを更新するにはどうすればよいですか?私が次のことを試してみると:

$site = Get-SPSite -Identity "http://vikas:26112/"

$web= $site.OpenWeb()   

$spList = $web.GetList("/Lists/Support Links") 
$spFieldType = [Microsoft.SharePoint.SPFieldType]::Text
$spList.Fields.Add("FirstName",$spFieldType,$false)
$spList.Fields[“FirstName”].Description = “My FirstName Field”
$spList.Fields[“FirstName”].Required=$true
$spList.Fields["FirstName"].EnforceUniqueValues=$true
$spList.update()

$web.Dispose()  

実行後、このFirstNameフィールドはリストに追加されますが、このフィールドのプロパティは変更されません。

Description =""  
Required=false  
EnforceUniqueValues=false  
4

1 に答える 1

6

問題は、フィールドを更新しておらず、インデクサーがフィールドを使用するたびに異なるインスタンスを返すことです。フィールドのインスタンスをいくつかの変数に格納し、それを変更してから更新する必要があります。

次のようにコードを変更します。

$site = Get-SPSite -Identity "http://vikas:26112/"
$web= $site.OpenWeb()   
$spList = $web.GetList("/Lists/Support Links") 
$spFieldType = [Microsoft.SharePoint.SPFieldType]::Text
$spList.Fields.Add("FirstName",$spFieldType,$false)
$field = $spList.Fields[“FirstName”]
$field.Description = “My FirstName Field”
$field.Required=$true
$field.EnforceUniqueValues=$true
$field.update()

$web.Dispose()  
于 2012-09-11T10:51:46.110 に答える