2017-12-01 31 views
0

配列を作成してフィールドのリストを格納できましたが、これをCSVファイルに変換しようとしています。しかし、すべての出力が文字列である必要があります。現在、文字列として出てきたテキストがありますが、たとえば文字列として出てくるノートが必要ですが、これはタクソノミの価値として出てきて、これを変更する方法がわからないのですか?以下は私の型をPowerShellの文字列に変換する方法

私はちょうど今持っている私のコードです:

# 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

出力は次のようになります。

「フィールド名」、「データ型」、「バリュー」

Site_type_0、ノート、当社ワイド

私は、文字列をしたいと思うとき、私は、分類データを取得するデータの種類が何であるかを書く

+5

CSVにエクスポートすると、自動的にデータがテキストに変換されます。希望の出力と実際の出力の例を示してください。 –

+0

のListItem \t ParentList Microsoft.SharePoint.SPListItemCollection \tサイト情報 Microsoft.SharePoint.SPListItemCollection \tサイト情報 –

+0

これは確かに「Microsoft.SharePoint.SPListItemCollection」は文字列でなければなりません、私はCSVファイルから取得されるものですか? –

答えて

0

私は.TypeAsStringを使用して多くのことを私を助け、私は次のことを行ってTaxonomyFieldTypeとTaxonomyFieldTypeMultiフィールドタイプのためにことがわかった:

"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 
     } 

ABを知っている誰もがある場合私が非常に興味を持っているので、私に知らせてください。

関連する問題