list - 用于获取所有列并输入 SPList 的 Powershell 脚本
问题描述
我想检索 SharePoint 列表中的所有列及其类型。我尝试了几个脚本,但结果不是我想要的。
以下是我尝试过的脚本:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Configuration Parameters
$SiteURL="http://url.com/"
$ListName= "theList"
$CSVPath="C:\Temp\list.csv"
#Get the Web and List
$Web = Get-SPWeb $SiteURL
$List = $Web.Lists.TryGetList($ListName)
#Export List Fields to CSV file
$List.Fields | select Title, InternalName | Export-Csv -path $CSVPath -NoTypeInformation
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$url = "http://url.com/"
$listName = "theList"
$path ="C:\Temp\list.csv"
$web = Get-SPWeb $url
$list = $web.Lists.TryGetList($listName)
$fields = $list.ContentTypes | %{ $_.FieldLinks }
$items = @() #array to store objects representing list items
$list.items | %{
$item = $_;
$hash = @{}; #hash table to store field name-value pairs
$fields | %{ $hash[$_.DisplayName] = $item[$_.Name] };
$items += new-object psobject -Property $hash }
$items | Export-Csv -Path $path
解决方案
只需添加 Type 属性。
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Configuration Parameters
$SiteURL="http://sp:12001"
$ListName= "Customers"
$CSVPath="C:\Lee\script\list.csv"
#Get the Web and List
$Web = Get-SPWeb $SiteURL
$List = $Web.Lists.TryGetList($ListName)
#Export List Fields to CSV file
$List.Fields | select Title, InternalName,Type | Export-Csv -path $CSVPath -NoTypeInformation
推荐阅读
- python-3.x - 错误:需要 Microsoft Visual C++ 14.0。使用“Microsoft Visual C++ 构建工具”获取它
- javascript - 为什么我的函数在第二次单击时不加载新的类名?
- kubernetes - kubernetes 1.18 堆叠控制平面和 etcd 节点无法添加第二个 ETCD 节点
- sql - 使用 SELECT 结果作为父 SELECT 的列名
- python - 是否可以将 python 项目的日志信息保存在局部变量中?
- ruby-on-rails - How to force Puma start in single mode on Rails?
- r - 如何将向量添加到 R 中的 NMDS?
- amazon-web-services - 具有代码管道和代码构建的 AWS Ci/Cd 管道
- php - 如何在 jQuery/Ajax 中将多个 PHP 变量传递给 PHP?这是我所有的代码
- java - 我怎样才能安全地向上转换一个 Optional?