Oct 17 2016 02:03 AM
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 how i can set it so it will be default on all sites.
thanks!
Oct 17 2016 03:15 AM
Oct 17 2016 05:56 AM - edited Oct 17 2016 05:57 AM
SolutionHTH. 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
Oct 17 2016 10:30 PM
Feb 22 2017 06:09 AM
Feb 22 2017 06:09 AM
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.
Nov 15 2017 07:45 AM
Would you please share how to do this on one document library?
Oct 17 2016 05:56 AM - edited Oct 17 2016 05:57 AM
SolutionHTH. 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