我已经能够创建一个数组并存储一个字段列表,我正在尝试将其转换为CSV文件。但是,我需要所有输出都是一个字符串。目前我的文字是以字符串形式出现的,但是例如我需要将我的笔记作为字符串出现,但它作为分类值而不确定如何更改?
以下是我刚才的代码:
# Get the web
$web = Get-SPWeb "specified_website"
# Get the target list
$list = $web.Lists["List_name"]
# Items used to hold the data
$Items = $list.Items
$array = @()
# Get all the items in the list
foreach ($item in $Items) {
$id = $item.id
Write-Host "Processing item number $id" -ForegroundColor Green
# every item has a Field e.g. my item has a title, etc.
foreach ($field in $item.Fields) {
# Get the type of the field
Write-Host $field.Type
# Print the field type out to a string
switch ($field.Type) {
"Text" { $msg = checkifTextisNull($item[$field.InternalName]) }
"Note" {
Write-Host $item[$field.InternalName] -ForegroundColor Cyan
}
"Lookup" { $item[$field.InternalName] -ForegroundColor Yellow }
"URL" { Write-Host $item[$field.InternalName] -ForegroundColor Magenta }
"Invalid" {
#Write-Host $item[$field.InternalName] -ForegroundColor Cyan
}
"Guid" { Write-Host $item[$field.InternalName]-ForegroundColor Yellow }
"Choice" { Write-Host $item[$field.InternalName] -ForegroundColor Cyan }
"Boolean" {
$msg = returnBooleanValue($item[$field.InternalName])
Write-Host $msg -ForegroundColor DarkCyan
}
"Computed" { Write-Host $item[$field.InternalName] -ForegroundColor White }
"Integer" {
Write-Host $item[$field.InternalName]
}
"User" { Write-Host $item[$field.InternalName] -ForegroundColor DarkGreen }
"DateTime" {
Write-Host $item[$field.InternalName] -ForegroundColor DarkGreen
}
"Number" { Write-Host $item[$field.InternalName] -ForegroundColor Yellow }
"Counter" { Write-Host $item[$field.InternalName] -ForegroundColor Green }
"Multi-Choice" {
Write-Host $item[$field.InternalName]
}
"Attachments" { Write-Host $item[$field.InternalName] -ForegroundColor Magenta }
"ModStat" { Write-Host $item[$field.InternalName] -ForegroundColor DarkGreen }
"File" { Write-Host $item[$field.InternalName] -ForegroundColor White }
}
}
# Add the object with property to Items
$array += $Items
}
我得到的输出是:
请注意
公司范围广| 0d3fbace-af9c-4f28-8be1-095e616893c0
我期望的输出是:
" FieldName"," DataType"," Value"
Site_type_0,注意,坚固
当我写出数据类型是什么时,我会得到分类数据,当我想要一个字符串时
答案 0 :(得分:0)
我发现使用.TypeAsString帮了我很多,而对于TaxonomyFieldType和TaxonomyFieldTypeMulti Field类型,我做了以下几点:
"TaxonomyFieldType"{
$FieldValue = $item[$field.InternalName] -as [Microsoft.SharePoint.Taxonomy.TaxonomyFieldValue];
$FieldValue = $FieldValue.Label;
$FieldValue
}
"TaxonomyFieldTypeMulti"{$FieldValueCollection = $item[$field.InternalName] -as [Microsoft.SharePoint.Taxonomy.TaxonomyFieldValueCollection];
foreach($Value in $FieldValueCollection) {
if($Value.label -ne $null)
{
$label = $Value.label
$guid = $Value.TermGuid.ToString()
$FieldValue+="Label = $label Guid = $guid;"
}
}
Write-Host $Value.label
}
如果有人知道更好的方式,请告诉我,因为我很想听到。