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
Anonymous
Oct 17, 2016Other thing you could think about is creating a contenttype for that than you don't need code but need to walk trough libraries to set the contenttype 1 time.
- AnonymousFeb 22, 2017
I was going to suggest the same about content type. This is a good reason to use content types, as they do make life much easier.