Forum Discussion
Off2w0rk
Oct 17, 2016Brass Contributor
Add column to default view
Hi all, is it possible to add additional column (ex language) to the default view on excisting and new document library on all sites? I know how to do this on one document library, but dont know...
- Oct 17, 2016
HTH. Limitatons of this script are
- Written using PnP PoserShell module
- Can be used for single site
- Add additional column in default view only for existing sites.
function ModifyView(){ Param( [Parameter(Mandatory=$True)] [Microsoft.SharePoint.Client.Web]$Web, [Parameter(Mandatory=$True)] [String]$ViewName, [Parameter(Mandatory=$True)] [String]$Columnname ) $DocumentLibrarys=Get-SPOList |?{$_.Basetemplate -eq "101" -and $_.Hidden -eq $false -and $_.IsCatalog -eq $false } foreach($DocumentLibrary in $DocumentLibrarys){ $view=$DocumentLibrary.Views $context.Load($view) $context.ExecuteQuery() $view2 = $view | ? { $_.Title -eq $ViewName } $view2.ViewFields.Add($Columnname); $view2.Update(); $web.Context.ExecuteQuery() } Write-Host "All Doucument Library View Updated" } $o365=Get-Credential $ViewName="All Documents" $Columnname="Version" Connect-SPOnline -Url https://<TenantName>.sharepoint.com/sites/teamsite -Credentials $o365 $context=get-spocontext $web=$context.Web $context.Load($web) $context.ExecuteQuery() ModifyView -web $web -ViewName $ViewName -Columnname $Columnname
SanthoshB1
Oct 17, 2016Bronze Contributor
HTH. Limitatons of this script are
- Written using PnP PoserShell module
- Can be used for single site
- Add additional column in default view only for existing sites.
function ModifyView(){ Param(
[Parameter(Mandatory=$True)]
[Microsoft.SharePoint.Client.Web]$Web,
[Parameter(Mandatory=$True)]
[String]$ViewName,
[Parameter(Mandatory=$True)]
[String]$Columnname
)
$DocumentLibrarys=Get-SPOList |?{$_.Basetemplate -eq "101" -and $_.Hidden -eq $false -and $_.IsCatalog -eq $false }
foreach($DocumentLibrary in $DocumentLibrarys){
$view=$DocumentLibrary.Views
$context.Load($view)
$context.ExecuteQuery()
$view2 = $view | ? { $_.Title -eq $ViewName }
$view2.ViewFields.Add($Columnname);
$view2.Update();
$web.Context.ExecuteQuery()
}
Write-Host "All Doucument Library View Updated"
}
$o365=Get-Credential
$ViewName="All Documents"
$Columnname="Version"
Connect-SPOnline -Url https://<TenantName>.sharepoint.com/sites/teamsite -Credentials $o365
$context=get-spocontext
$web=$context.Web
$context.Load($web)
$context.ExecuteQuery()
ModifyView -web $web -ViewName $ViewName -Columnname $Columnname