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

51CTO 博客地址:https://blog.51cto.com/13969817
博客园博客地址:https://www.cnblogs.com/bxapollo

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

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

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

  • 加载SharePoint Online Assemblies
  • 自定义函数从给定的站点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",如下所示:

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

说明:加载这两个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

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

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

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

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

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

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

猜你喜欢

转载自blog.51cto.com/13969817/2590482