簡體   English   中英

SharePoint Online 和 PNP PowerShell - 在所有元數據中將庫文檔輸出到 CSV,包括內容類型

[英]SharePoint Online & PNP PowerShell - output a libraries documents to CSV within all metadata, including CONTENT TYPE

我一直在使用以下內容將 SharePoint Online 文檔庫作為 CSV 輸出,包括所有自定義元數據字段屬性。

但是,我無法獲得分配的內容類型。 我將其視為標准列,但想象一下還有更多內容嗎? 我似乎無法找到任何相關的內容。

#Parameters
$SiteURL = "https://SHAREPOINT URL"
$ListName= "LIBRARYNAME"
$ReportOutput = "C:\LOCATION.csv"
$Pagesize = 500
   
#Connect to SharePoint Online site
Connect-PnPOnline $SiteURL -UseWebLogin
 
#Delete the Output report file if exists
If (Test-Path $ReportOutput) { Remove-Item $ReportOutput}
 
#Array to store results
$Results = @()
   
#Get all Documents from the document library
$List  = Get-PnPList -Identity $ListName
$global:counter = 0;
$ListItems = Get-PnPListItem -List $ListName -PageSize $Pagesize -Fields Author, Editor, Created, File_x0020_Type, Business_x0020_Unit, Department, Device, Document_x0020_Type, Employee_x0020_Status, Retention_x0020_Period, Scan_x0020_Date, Scanned_x0020_by, Staff_x0020_ID, Staff_x0020_Name, ContentType -ScriptBlock `
        { Param($items) $global:counter += $items.Count; Write-Progress -PercentComplete ($global:Counter / ($List.ItemCount) * 100) -Activity `
             "Getting Documents from Library '$($List.Title)'" -Status "Getting Documents data $global:Counter of $($List.ItemCount)";} | Where {$_.FileSystemObjectType -eq "File"}
  
$ItemCounter = 0
#Iterate through each item
Foreach ($Item in $ListItems)
{
        $Results += New-Object PSObject -Property ([ordered]@{
            Name              = $Item["FileLeafRef"]
            Type              = $Item.FileSystemObjectType
            FileType          = $Item["File_x0020_Type"]
            RelativeURL       = $Item["FileRef"]
            CreatedByEmail    = $Item["Author"].Email
            CreatedOn         = $Item["Created"]
            Modified         = $Item["Modified"]
            ModifiedByEmail    = $Item["Editor"].Email
            BusinessUnit = $Item["Business_x0020_Unit"]
            Department = $Item["Department"]
            Device = $Item["Device"]
            DocumentType = $Item["Document_x0020_Type"]
            EmployeeStatus = $Item["Employee_x0020_Status"]
            RetentionPeriod = $Item["Retention_x0020_Period"]
            ScanDate = $Item["Scan_x0020_Date"]
            ScannedBy = $Item["Scanned_x0020_by"]
            StaffID = $Item["Staff_x0020_ID"]
            StaffName = $Item["Staff_x0020_Name"]
            ContentType = $Item["ContentType"]
        })
    $ItemCounter++
    Write-Progress -PercentComplete ($ItemCounter / ($List.ItemCount) * 100) -Activity "Exporting data from Documents $ItemCounter of $($List.ItemCount)" -Status "Exporting Data from Document '$($Item['FileLeafRef'])"        
}
  
#Export the results to CSV
$Results | Export-Csv -Path $ReportOutput -NoTypeInformation
   
Write-host "Document Library Inventory Exported to CSV Successfully!"

歡迎提供有關如何捕獲庫項目所涉及的內容類型的任何指示!

嘗試這個:

$ctx = Get-PnPContext
Foreach ($Item in $ListItems)
 {
$Ctx.Load($Item.ContentType)
$Ctx.ExecuteQuery()
 write-host $Item.ContentType.Name
 }

測試結果:

在此處輸入圖片說明

更新:

 $ctx = Get-PnPContext
Foreach ($Item in $ListItems)
{
 $Ctx.Load($Item.ContentType)
    $Ctx.ExecuteQuery()
        $Results += New-Object PSObject -Property ([ordered]@{
            Name              = $Item["FileLeafRef"]
            Type              = $Item.FileSystemObjectType
            FileType          = $Item["File_x0020_Type"]
            RelativeURL       = $Item["FileRef"]
            CreatedByEmail    = $Item["Author"].Email
            CreatedOn         = $Item["Created"]
            Modified         = $Item["Modified"]
            ModifiedByEmail    = $Item["Editor"].Email
            BusinessUnit = $Item["Business_x0020_Unit"]
            Department = $Item["Department"]
            Device = $Item["Device"]
            DocumentType = $Item["Document_x0020_Type"]
            EmployeeStatus = $Item["Employee_x0020_Status"]
            RetentionPeriod = $Item["Retention_x0020_Period"]
            ScanDate = $Item["Scan_x0020_Date"]
            ScannedBy = $Item["Scanned_x0020_by"]
            StaffID = $Item["Staff_x0020_ID"]
            StaffName = $Item["Staff_x0020_Name"]
            ContentType = $Item.ContentType.Name
        })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM