我正在运行以下ps脚本以获取一些数据到csv。 person字段(AssignedTo和CreatedBy)带有索引; #LastName,FirstName。如何在没有索引的情况下获取名称。或者我需要进行正则表达式还是替换?例如,
32;#Doe,John应该是Doe,John
$results = @()
$web = Get-SPWeb "http://ourlocal.company.cc/docs/sales"
$list = $web.Lists["Sales Tasks"]
$caml = '<Where><Eq><FieldRef Name="Status" /><Value Type="Choice">Completed</Value></Eq></Where>'
$query=new-object Microsoft.SharePoint.SPQuery
$query.Query=$caml
$ListItems=$list.GetItems($query)
Write-Host "count " $ListItems.Count
foreach ($item in $listItems)
{
$Title = $item["Title"]
$AssignedTo = $item["AssignedTo"]
$Status = $item["Status"]
$Priority = $item["Priority"]
$CreatedBy = $item["Created By"]
$out = new-object psobject -Property @{Title = $Title
AssignedTo = $AssignedTo
Status = $Status
Priority = $Priority
"Due Date" = $DueDate
"Percent Complete" = $Percent
"Created by" = $CreatedBy}
$out = $out|select-object Title, AssignedTo, Status, Priority, "Due Date", "Percent Complete", "Created by"
$results +=$out
}
$results | Export-Csv "c:\output.csv" -noType
$web.Dispose()
答案 0 :(得分:6)
第1步:
在$ CreatedBy = $ item之后添加以下代码[&#34;由&#34;创建]
$CreatedByUserObj = New-Object Microsoft.SharePoint.SPFieldUserValue($web, $CreatedBy)
$CreatedByDisplayName = $CreatedByUserObj.User.DisplayName;
第2步:
替换&#34;由&#34;创建= $ CreatedBy,代码如下
"Created by" = $CreatedByDisplayName