繁体   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