SharePoint 解决方案:如何获取所有List Template?

51CTO博客地址:https://blog.51cto.com/1396817

博客园博客地址:https://www.cnblogs.com/bxapollo

由于某种原因,用户或者Division Admin需要获取当前SharePoint Online网站的List Template情况,来确定是否有Customization,是否可以做数据搬迁或者了解用户的使用情况等等,那么作为SharePoint Online Admin该如何来抓取这部分数据呢?

今天给大家分享一下,如何用脚本获取某个特定的Site Collection下的List Template以及相关描述。

执行脚本分以下2个步骤:

  1. 加载 SharePoint Online Assemblies
  2. 自定义函数从给定的站点 URL 获取所有的列表模板

加载 SharePoint Online Assemblies 的命令:

•	Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
•	Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

但由于我环境的.net是 4.0,默认的情况下,禁用从远程位置加载的程序集中执行代码的能力,所以需要使用[System.Reflection.Assembly]::LoadFrom()来加载Microsoft.SharePoint.Client.dll,如下所示:

 

说明:加载这两个dll文件,需要在部署SharePoint Server端执行,否则默认的情况下物理路径是没有该文件的。

自定义函数从给定的站点URL获取所有的列表模板

$SiteURL="https://mvptrainingcn.sharepoint.com/sites/Demo2"
    #Get Credentials to connect
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
   
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials
 
    #Get All list templates
    $ListTemplates=$Ctx.Web.ListTemplates
    $Ctx.Load($ListTemplates)
    $Ctx.ExecuteQuery()
 
    #Get All Available list templates
        $ListTemplates | Select Name, Description, ListTemplateTypeKind| Sort-Object Name | Format-Table -AutoSize

在弹出的页面,输入Office 365 Global Admin的账户和密码,之后就会加载Demo网站的List template以及对应的描述了,如下所示:

 

 为了帮助 大家查看,也可以直接从下表中获取相关信息:

 

 

 

 这样,我们就获取到所有的list template的情况下,包含Customization Template,希望本文对大家有所帮助,谢谢阅读。

posted @ 2021-01-14 11:30  bxapollo  阅读(209)  评论(0编辑  收藏  举报