2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PowerShell で SharPoint のリストビューの表示列を設定する

2
Posted at
Add-PSSnapin Microsoft.SharePoint.PowerShell
$ErrorActionPreference = "Stop"

# ビューの表示列を更新
# 引数は、サイトURL($WebUrl), リスト表示名($ListDisplayName)、ビュー表示名($ViewName)、ビューに表示する列の内部名の配列
function setViewFields( $WebUrl, $ListDisplayName, $ViewName, $ViewFields ) {
    # サイト取得
    $web  = Get-SPWeb $WebUrl
    Write-Host "Web : $($web.Title)"

    # リスト取得
    $list = $web.Lists | ?{ $_.title -eq $ListDisplayName }
    Write-Host "List : $($list.Title)"

    # ビュー取得
    $view = ($list.Views | ?{ $_.Title -eq $viewName} )[0]
    Write-Host "View :  $($view.Title)"

    # ビュー表示列取得
    $fields = $view.ViewFields
    # ビュー表示列初期化
    Write-Host ("{0} fields clear in view." -F $fields.Count)
    $fields.DeleteAll()
    
    # ビュー表示列追加
    foreach( $field in $ViewFields ) {
        $f = $list.Fields.GetFieldByInternalName($field)
        Write-Host ("Add [{0} ( {1} )] field" -F $f.Title, $field)
        $fields.Add( $field )
    }

    # ビュー更新
    Write-Host "View update."
    $view.Update()
}
# 使用例 -----------------------------------------------------------------
$webUrl          = "http://hoge/sites/honsya/shashi_hensan_shitsu"
$listDisplayName = "Xファイル置き場"
$viewName        = "未解決一覧"
$viewFields      = (
      "Title" `
    , "ID" `
    , "AssignTo" `
    , "IsUMO" `
    )

setViewFields -WebUrl $webUrl -ListDisplayName $listDisplayName -ViewName $viewName -ViewFields $ViewFields
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?